Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Business days calculation broken in 0.7.5 #132

Open
bmulholland opened this issue Apr 7, 2016 · 8 comments
Open

Business days calculation broken in 0.7.5 #132

bmulholland opened this issue Apr 7, 2016 · 8 comments

Comments

@bmulholland
Copy link

0.7.4

2.2.3 :004 > Time.now.in_time_zone("America/Los_Angeles")
 => Thu, 07 Apr 2016 12:35:15 PDT -07:00
2.2.3 :005 > 2.business_days.from_now.in_time_zone("America/Los_Angeles")
 => Mon, 11 Apr 2016 12:35:19 PDT -07:00

0.7.5

2.2.3 :004 > Time.now.in_time_zone("America/Los_Angeles")
 => Thu, 07 Apr 2016 12:35:00 PDT -07:00
2.2.3 :005 > 2.business_days.from_now.in_time_zone("America/Los_Angeles")
 => Tue, 12 Apr 2016 02:00:00 PDT -07:00
@bmulholland
Copy link
Author

Likewise

0.7.4

2.2.3 :006 > 2.business_days.ago.in_time_zone("America/Los_Angeles")
 => Tue, 05 Apr 2016 12:37:26 PDT -07:00

0.7.5

2.2.3 :006 > 2.business_days.ago.in_time_zone("America/Los_Angeles")
 => Tue, 05 Apr 2016 02:00:00 PDT -07:00

@muzfuz
Copy link

muzfuz commented Apr 12, 2016

From lib/business_time/business_time.rb

      if time.is_a?(Time) || time.is_a?(DateTime)
        unless time.during_business_hours?
          time = Time.beginning_of_workday(Time.roll_backward(time))
        end
      end

Looks to me to be done on purpose.

It seems to be one of the biggest changes is around handling of business days now being defaulted to 9am to 5pm, instead of 12am to 11:59pm.

Make sure you generate your yaml config file (using generator in the README), and change the settings there if you were relying on anything like that.

@bmulholland
Copy link
Author

That's a pretty big change to introduce in a point version :(

@muzfuz
Copy link

muzfuz commented Apr 12, 2016

Agreed. I think this should have followed semantic versioning. Lack of a changelog is problematic as well.

@ladelfa
Copy link

ladelfa commented Jun 1, 2016

Ditto. If it's 2:25 pm on Wednesday, I would expect 1.business_day.ago to be 2:25 pm on Tuesday, not the beginning of the business day on Tuesday, whatever that's set to be.

@bokmann
Copy link
Owner

bokmann commented Jun 9, 2016

this was an accident. I'm looking into it now. Accepting multiple pull requests, dealing with monkeypatches on top of ActiveSupport Monkeypatches becomes a lot to deal with. Future versions will have a change log.

@bokmann
Copy link
Owner

bokmann commented Jun 9, 2016

I am not seeing the issue you describe above. Here I am with your test cases:

Time.now
  2016-06-09 10:37:42 -0400
2.business_days.ago
  2016-06-07 10:37:58 -0400
2.business_days.ago.in_time_zone("America/Los_Angeles")
  Tue, 07 Jun 2016 07:38:22 PDT -07:00
Time.now.in_time_zone("America/Los_Angeles")
  Thu, 09 Jun 2016 07:38:51 PDT -07:00
2.business_days.from_now.in_time_zone("America/Los_Angeles")
  Mon, 13 Jun 2016 07:39:03 PDT -07:00

Can you tell me:

  • The Activesupport version you are using?
  • The version of your TZInfo Gem?
  • What version of Ruby you are using?

Or even better, a failing test case added to the tests?

@ladelfa
Copy link

ladelfa commented Jun 9, 2016

This issue may have an interaction with the stub method of rspec 2.x and this way of writing time-deterministic tests :

Time.stub(now: Time.utc(2014, 6, 3, 10, 10))
=> {:now=>2014-06-03 10:10:00 UTC}
1.business_day.ago
=> Mon, 02 Jun 2014 06:10:00 EDT -04:00

Time.stub(now: Time.new(2014, 6, 3, 10, 10))
=> {:now=>2014-06-03 10:10:00 -0700}
1.business_day.ago
=> Mon, 02 Jun 2014 00:00:00 EDT -04:00

Under 0.7.4, stubbing with utc and new give identical responses:

Time.stub(now: Time.utc(2014, 6, 3, 10, 10))
=> {:now=>2014-06-03 10:10:00 UTC}
1.business_day.ago
=> Mon, 02 Jun 2014 06:10:00 EDT -04:00

Time.stub(now: Time.new(2014, 6, 3, 10, 10))
=> {:now=>2014-06-03 10:10:00 -0700}
1.business_day.ago
=> Mon, 02 Jun 2014 13:10:00 EDT -04:00

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants