Skip to content

Fix datetime formatting and update timezone default handling#2779

Merged
nickcharlton merged 1 commit intothoughtbot:mainfrom
goosys:2702-refactor-datetime-format
Feb 18, 2025
Merged

Fix datetime formatting and update timezone default handling#2779
nickcharlton merged 1 commit intothoughtbot:mainfrom
goosys:2702-refactor-datetime-format

Conversation

@goosys
Copy link
Copy Markdown
Contributor

@goosys goosys commented Feb 18, 2025

  • refs Refactor Time-related Fields ahead of upcoming improvements #2702
  • Ensured consistency across public methods for DateTime, Date, and Time, which each had slight differences.
  • Removed the default option from I18n.localize:
    • Since an exception is thrown with data.in_time_zone when data is nil, the default option was not meaningful.
  • Removed the default value for timezone and removed string conversion with .name:
    • Time.zone is always defined, so a default value is unnecessary.
    • in_time_zone can accept Time.zone objects directly, so string conversion is also unnecessary.

This ensures consistency across public methods for `DateTime`, `Date`,
and `Time` which all had slight differences.

We remove the `default` option from `I18n.localize`, because an
exception is thrown with `data.in_time_zone` when the `data` is `nil`,
the `default` option is not meaningful.

We don't need a fallback for the time zone, as with `Time.zone`, one is
already defined. We also don't need to do a string conversion, as
`in_time_zone` supports accepting a `Time.zone` object.
@nickcharlton nickcharlton force-pushed the 2702-refactor-datetime-format branch from 8b52417 to f2feb7c Compare February 18, 2025 16:29
@nickcharlton nickcharlton merged commit ca92ab8 into thoughtbot:main Feb 18, 2025
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

Successfully merging this pull request may close these issues.

2 participants