Refactor Time-related Fields ahead of upcoming improvements #2702
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I initially planned to improve the i18n for Time-related fields, but I realized some preliminary refactoring was necessary. I’ve made a few small adjustments and would appreciate your review.
Field::Time#time
to always go throughI18n.localize
:format
option wasn’t specified, it bypassedtranslate_localization_format
, so AM/PM was not localized.default
option fromI18n.localize
:data.in_time_zone
whendata
isnil
, thedefault
option was not meaningful..name
:in_time_zone
can acceptTime.zone
objects directly, so string conversion is also unnecessary.Customer.example_time
to the Dashboard in the example app to check the behavior of theField::Time
.rails-i18n
gem, we don’t have to worry about am/pm translations being undefined.Next, I’d like to make the following adjustments. What do you think?
options.fetch(:format, :administrate_datetime_default)
as the default format value:default
format used in the main application outside of the Administrate panel."%I:%M%p"
, but in Japanese, we would prefer the order"%p %I:%M"
. I believe other languages may also have their own preferred orders.format
option to be passed into public methods.field.time(format: :administrate_time_short)
, while in the show view, simply callingfield.time
would apply:administrate_time_default
.