Business hours processing

Hi,
I need to determine how many business hours left to some Time. Do you
know any library with this feature?

SÅ‚awosz

2010/6/11 SÅ‚awosz SÅ‚awiÅ„ski [email protected]:

Hi,
I need to determine how many business hours left to some Time. Do you
know any library with this feature?

SÅ‚awosz

Posted via http://www.ruby-forum.com/.

Not sure what you mean by “business hours”, but if it is the same a
regular hour, and you have an end time (5 PM, for example) you can
simply subtract the two time objects. For example:

time_left = Time.parse(“17:00”) - Time.now

If “business hours” means something special, please explain.

Ammar

Not sure what you mean by “business hours”, but if it is the same a
regular hour, and you have an end time (5 PM, for example) you can
simply subtract the two time objects. For example:

time_left = Time.parse(“17:00”) - Time.now

If “business hours” means something special, please explain.

It means this. For example, there is
GitHub - bokmann/business_time: Support for doing time math in business hours and days but I need somethink like

Time.now.business_time_left_to(Time.parse(“Aug 5 2010, 9:35 am”))

and it should returns how many business hours and minutes left.
Or I will fork business_time gem.

Thanks,
as solution, I wrote very simple extension to business_time:

I wish it would help someone :slight_smile:

SÅ‚awosz

2010/6/11 SÅ‚awosz SÅ‚awiÅ„ski [email protected]

Hi,
I need to determine how many business hours left to some Time. Do you
know any library with this feature?

SÅ‚awosz

Posted via http://www.ruby-forum.com/.

From
http://www.rubyinside.com/3-new-date-and-time-libraries-for-rubyists-3238.html

business_time - Time and date offsets based on “business time/hours”

business_time is a new library that works with the concept of “business
time” or “business hours.” Rather than just letting you perform
operations
on dates by absolute numbers of days or hours, you can now work with
business days and hours of your own definition. business_time depends
heavily on Active Support.

To install:

gem install business_time

Note: business_time depends on Active Support (gem: activesupport)

To use:

require ‘active_support’
require ‘business_time’

Examples “from now”

4.business_hours.from_now
5.business_days.from_now

Using user supplied dates

my_birthday = Date.parse(“August 4th, 2010”)
10.business_days.before(my_birthday)

Add a day to not count as a business day

BusinessTime::Config.holidays << my_birthday

Overlapping days are OK

6.business_hours.after(Time.parse(“August 3rd, 3:00pm”))