-
Notifications
You must be signed in to change notification settings - Fork 215
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
Odd timezone behavior as soon as integrated with Rails #93
Comments
ok, when I mean 'timezone agnostic', I mean that it makes no assumptions about timezones and should work if you use one consistently. If you set the Rails timezone to UTC and then pass in times that are in a different timezone than that, that probably will result in some pretty wonky behavior. Lets say you set your workday to be 9:00am - 5:00pm, and your server time to be EST. Argument #2 - "I configured my app so that business hours were 9 to 5 in EST, and 6:05 PST is within 9-5EST, so this should be inside of work hours" I do not think there is a 'right' answer to that question, there is only the answer you want in the context of your business requirements. Converting all times to a standard time zone before asking these questions removes the ambiguity. Or am I missing your question? |
I think you mixed up your EST and PST, but yes I understand what you're saying. Either argument would be fine if you picked one and stuck with it, but the current behavior is inconsistent. I've tried to demonstrate this below: (FYI, my system timezone is Pacific time) Scenario 1:
You can see here that it seems to behave as described in argument 1. It just ignores the timezones and returns objects in the same timezone I passed in. However, the moment I load in my rails environment, the behavior changes, likely because Rails initializes my Time.zone variable from "nil" to "Eastern Time", which is currently default in my Rails environment.
You can see I passed in a UTC time, but the functions are now suddenly converting my UTC time to EST time. The library has suddenly switched to the logic from argument 2 now that Rails is loaded. The core of the problem seems to come down to the state of the Time.zone variable. If it's "nil", it consistently behaves as you described in argument 1. If you set Time.zone to anything else, it suddenly starts to behave as described in argument 2. This can be very confusing, especially when you develop the script outside of a rails environment where Time.zone is nil, and then once you integrate with Rails you find that it behaves completely different. I think that it should pick one or the other behavior and stick with it. |
I got around this by setting timezone in application.rb: config.timezone = 'Melbourne'. Seems to be working for now...I'm using 4.business_hours.from_now, 8.business_hours.from_now, 18.business_hours.from_now, 45.business_hours.from_now. Although it doesn't seem to work if I add a holiday to the business_time.yml. But I had to do it with Businestime::Config... |
As I read your transcript, I'm not surprised this is happening at all.
When used with Rails, business_time should be configured in a rails initializer so that it is configured after rails is. While business_time is timezone-agnostic, rails is not. It is very timezone-opinionated, and that is what is causing this behavior. I'm moving this conversation to the 'requires discussion' milestone, because I want to make sure we understand each other before I close this out. |
Did you guys understood each other? :D |
I ran into a very similar issue as #36, but different enough that I think it deserves a new ticket. I had a script using Business Time that was working just fine for a long time. As soon as I tried to integrate it into my Rails environment, my times started getting butchered. Here is the logic that seemed to be causing my issues:
https://github.com/bokmann/business_time/blob/develop/lib/business_time/time_extensions.rb#L107
Before I integrated Rails, Time.zone was nil. After adding Rails, Time.zone was always set to UTC. My timezone that I was trying to use (passed in the "time" variable) was in UTC-400.
For now I've solved this by setting my Rails timezone to the same timezone that I'm passing into my Business Time functions and that seems to have solved it, however as Business Time is supposed to be timezone agnostic, it would be nice to see this fixed and be able to go back to UTC in my rails app.
Edit: removed note about the new release that was mentioned in #36 after I noticed that the discussion was over a year old.
The text was updated successfully, but these errors were encountered: