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

Active Support time zone offset #42473

Closed
gabriel-curtino opened this issue Jun 14, 2021 · 3 comments
Closed

Active Support time zone offset #42473

gabriel-curtino opened this issue Jun 14, 2021 · 3 comments

Comments

@gabriel-curtino
Copy link

ActiveSupport and TZInfo utc_offset return different values. TZinfo gives the correct current offset value (EDT UTC-4h) for today.

Expected behavior

#> Time.find_zone("America/New_York").utc_offset
=> -14400 # -04:00
#> Time.find_zone("America/New_York").tzinfo.utc_offset
=> -14400 # -04:00

Actual behavior

#> Time.find_zone("America/New_York").utc_offset
=> -18000 # -05:00
#> Time.find_zone("America/New_York").tzinfo.utc_offset
=> -14400 # -04:00

System configuration

Rails version: 6.1.3.2
Ruby version: 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]

@airled
Copy link

airled commented Jun 14, 2021

#42467 Related?

@gabriel-curtino
Copy link
Author

#42467 Related?

I don't think so... it doesn't seems just a daylight savings difference there.

@gabriel-curtino
Copy link
Author

gabriel-curtino commented Jun 14, 2021

tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period

Find out that ActiveSupport::Timezone.utc_offset comes form TZInfo::TimezonePeriod.utc_offset that says (2):

Returns the base offset from UTC in seconds (observed_utc_offset - std_offset). This does not include any adjustment made for daylight savings time and will typically remain constant throughout the year.

To obtain the currently observed offset from UTC, including the effect of daylight savings time, use #observed_utc_offset instead.

I'm expecting to get the current offset because I'm creating a DateTime in an specific timezone but got it wrong. It has not to be like I was expecting although I think it makes more sense to retrieve the current offset or at least document that ActiveSupport::Timezone.utc_offset retrieves the "base" offset... and maybe a new method to get the current one?

Well, I don't think anymore this is a bug.

(2) https://rubydoc.info/gems/tzinfo/TZInfo/TimezonePeriod#base_utc_offset-instance_method

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

No branches or pull requests

2 participants