business_time
business_time copied to clipboard
inconsistent business day calculation between sunday afternoon and monday AM
When calculating 0.business_days.from_now on a Sunday, I am given Tuesday. But then if I run 0.business_days.from_now again before the start of business on Monday, I am finally given Monday..
Run on Sunday afternoon:
[1] pry(main)> 1.business_day.from_now => Wed, 17 Aug 2016 09:00:00 EDT -04:00 [2] pry(main)> 0.business_day.from_now => Tue, 16 Aug 2016 09:00:00 EDT -04:00 [3] pry(main)> 0.business_day.ago => Fri, 12 Aug 2016 09:00:00 EDT -04:00 [4] pry(main)> 1.business_day.ago => Thu, 11 Aug 2016 09:00:00 EDT -04:00
Run on Monday at 8 am EDT:
[5] pry(main)> 0.business_day.from_now => Mon, 15 Aug 2016 09:00:00 EDT -04:00 [6] pry(main)> 1.business_day.from_now => Tue, 16 Aug 2016 09:00:00 EDT -04:00
@philrosenstein Have you considered the biz
gem? (I'm the maintainer.)
It exhibits behavior that might fit your use case well:
>> SUNDAY_AFTERNOON = Time.utc(2016, 8, 14, 14)
=> 2016-08-14 14:00:00 UTC
>> MONDAY_MORNING = Time.utc(2016, 8, 15, 8)
=> 2016-08-15 08:00:00 UTC
>> 1.business_day.after(SUNDAY_AFTERNOON)
=> 2016-08-15 14:00:00 UTC
>> 0.business_days.after(SUNDAY_AFTERNOON)
=> 2016-08-15 09:00:00 UTC
>> 0.business_days.before(SUNDAY_AFTERNOON)
=> 2016-08-12 17:00:00 UTC
>> 1.business_day.before(SUNDAY_AFTERNOON)
=> 2016-08-12 14:00:00 UTC
>> 0.business_days.after(MONDAY_MORNING)
=> 2016-08-15 09:00:00 UTC
>> 1.business_day.after(MONDAY_MORNING)
=> 2016-08-16 09:00:00 UTC
this seems to be related to #149
I'll get a test case and investigate