Project

roxbury

0.0
No release in over 3 years
Low commit activity in last 3 years
A Ruby library for handling business days calculations, e.g., working days/hours between two dates, add working days/hours to a date, etc.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 2.0
>= 0
>= 0
~> 13.0
~> 3.0

Runtime

 Project Readme

Roxbury

A Ruby library for handling business days calculations, e.g., working days/hours between two dates, add working days/hours to a date, etc.

It was extracted from a production application that's been running for many years.

Build Status

Installation

Add this line to your application's Gemfile:

gem 'roxbury'

And then execute:

$ bundle

Usage

calendar = Roxbury::BusinessCalendar.new(
  working_hours: {
    'Mon' => 9..17,
    'Tue' => 9..17,
    'Wed' => 9..17,
    'Thu' => 9..17,
    'Fri' => 9..17,
    'Sat' => 9..13
  }
)

calendar.working_days_between(Date.new(2019, 8, 1), Date.new(2019, 8, 5))
# => 3.5

calendar.add_working_days(Date.new(2019, 8, 3), 1)
# => Date.new(2019, 8, 5)

calendar.add_working_days(Time.new(2019, 8, 3, 9, 0), 1)
# => Time.new(2019, 8, 5, 13, 0)

calendar.working_hours_between(Time.new(2019, 8, 2, 8, 0), Time.new(2019, 8, 3, 14, 0))
# => 12

calendar.roll_forward(Time.new(2019, 8, 4))
# => Time.new(2019, 8, 5, 9, 0)

Please refer to the tests in spec/roxbury/business_calendar_spec.rb for more examples.

Holidays

You can specify the list of holidays in the constructor:

calendar = Roxbury::BusinessCalendar.new(
  working_hours: Hash.new(9..17),
  holidays: [Date.new(2019, 12, 25)]
)

calendar.working_days_between(Date.new(2019, 12, 24), Date.new(2019, 12, 26))
# => 2.0

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/eeng/roxbury. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Code of Conduct

Everyone interacting in the Roxbury project’s codebases and issue trackers is expected to follow the code of conduct.