# Business hours processing

**URL:** <https://www.ruby-forum.com/t/business-hours-processing/190032>\
**Category:** Ruby\
**Created:** [June 11, 2010, 7:58pm UTC](https://www.ruby-forum.com/t/business-hours-processing/190032 "2010-06-11T19:58:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![slawosz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@slawosz](https://www.ruby-forum.com/u/slawosz)\
**Post date:** [June 11, 2010, 7:58pm UTC](https://www.ruby-forum.com/t/business-hours-processing/190032/1 "2010-06-11T19:58:26Z")

</div>

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

SÅ‚awosz

---

<div class="post-metadata">

**Author:** ![slawosz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@slawosz](https://www.ruby-forum.com/u/slawosz)\
**Post date:** [June 11, 2010, 8:13pm UTC](https://www.ruby-forum.com/t/business-hours-processing/190032/2 "2010-06-11T20:13:14Z")

</div>

2010/6/11 SÅ‚awosz SÅ‚awiÅ„ski [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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/](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

---

<div class="post-metadata">

**Author:** ![slawosz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@slawosz](https://www.ruby-forum.com/u/slawosz)\
**Post date:** [June 11, 2010, 8:21pm UTC](https://www.ruby-forum.com/t/business-hours-processing/190032/3 "2010-06-11T20:21:44Z")

</div>

> 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](http://github.com/bokmann/business_time) 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.

---

<div class="post-metadata">

**Author:** ![slawosz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@slawosz](https://www.ruby-forum.com/u/slawosz)\
**Post date:** [August 3, 2010, 5:10pm UTC](https://www.ruby-forum.com/t/business-hours-processing/190032/4 "2010-08-03T17:10:26Z")

</div>

Thanks,  
as solution, I wrote very simple extension to business\_time:

> **[GitHub - slawosz/business\_seconds: Extension for bokmann/business\_time to...](https://github.com/slawosz/business_seconds)**
>
> Extension for bokmann/business\_time to calculate business seconds between two time instances - GitHub - slawosz/business\_seconds: Extension for bokmann/business\_time to calculate business seconds b...

I wish it would help someone 🙂

SÅ‚awosz

---

<div class="post-metadata">

**Author:** ![slawosz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@slawosz](https://www.ruby-forum.com/u/slawosz)\
**Post date:** [June 11, 2010, 8:57pm UTC](https://www.ruby-forum.com/t/business-hours-processing/190032/5 "2010-06-11T20:57:44Z")

</div>

2010/6/11 SÅ‚awosz SÅ‚awiÅ„ski [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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/](http://www.ruby-forum.com/).

From  
[http://www.rubyinside.com/3-new-date-and-time-libraries-for-rubyists-3238.html](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”))
