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

TZ offset minute has to be negated in the Western Hemisphere #46872

Merged
merged 1 commit into from Jan 17, 2024

Conversation

amatsuda
Copy link
Member

@amatsuda amatsuda commented Jan 3, 2023

This patch fixes a bug in our AMo Time type caster that it doesn't handle minus offset in a given string correctly.

Background / Detail

When the TZ in the given string contains minus offset, both hour and minute value has to be negated, but the current code nagates hour only.

For instance in Newfoundland Time Zone (UTC−03:30), the offset part goes like "-03:30" which has to be treated as "-3 hours and -30 minutes", but it used to be calculated as "-3 hours and +30 minutes", then it used to return 1 hour advanced value than the actual.

Additional information

Parsing Time ourselves is too hard for non-professional. This bug may tell why I'm proposing to switch to Ruby's built in Time parser in #46868. And, this bug was found and reported by Time pro @nobu via https://bugs.ruby-lang.org/issues/19293#note-1 (thanks!)

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

When the TZ in the given string contains minus offset, both hour and minute
value has to be negated, but the current code negates hour only.
Hence, for instance in Newfoundland Time Zone (UTC−03:30), it used to return
1 hour advanced value.

Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
@amatsuda amatsuda merged commit a71e0aa into rails:main Jan 17, 2024
4 checks passed
@amatsuda amatsuda deleted the fast_string_to_time_bug branch January 17, 2024 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants