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

Time#change should pass the zone property through if it's set #42583

Merged
merged 1 commit into from Jun 26, 2021

Conversation

ghiculescu
Copy link
Member

Fixes #42467

@@ -159,6 +159,8 @@ def change(options)
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec, new_offset)
elsif utc?
::Time.utc(new_year, new_month, new_day, new_hour, new_min, new_sec)
elsif zone && zone.is_a?(ActiveSupport::TimeZone)
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec, zone)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my first attempt at a fix merged this branch and the next one, but Time.new doesn't like zones formatted as some kinds of strings, eg. it was crashing on ::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec, "CST")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.zone isn't necessarily an instance of ActiveSupport::TimeWithZone - Ruby allows any object there as long as it quacks in the correct manner. Perhaps a zone.respond_to?(:utc_to_local) would be better?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the docs I was trying to find! I'll tidy it up, thanks.

@zzak
Copy link
Member

zzak commented Jun 24, 2021

@ghiculescu Can you add a changelog too plz? 🙇

@ghiculescu
Copy link
Member Author

👍 changelog added

@zzak zzak added the ready PRs ready to merge label Jun 25, 2021
Copy link
Contributor

@pixeltrix pixeltrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that Time instances with zone objects has a few more bugs lurking in Active Support 😬

@pixeltrix pixeltrix merged commit beb9635 into rails:main Jun 26, 2021
pixeltrix added a commit that referenced this pull request Jun 26, 2021
Backport #42583: `Time#change` should pass the `zone` property through if it's set
@ghiculescu ghiculescu deleted the time-change-with-zone branch June 26, 2021 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
activesupport ready PRs ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Time manipulation inconsistency with ActiveSupport::TimeZone
4 participants