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

Refactor Time-related Fields ahead of upcoming improvements #2702

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

goosys
Copy link
Contributor

@goosys goosys commented Nov 7, 2024

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.

  • Ensured consistency across public methods for DateTime, Date, and Time, which each had slight differences.
  • Updated Field::Time#time to always go through I18n.localize:
  • 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.
  • Added Customer.example_time to the Dashboard in the example app to check the behavior of the Field::Time .
  • Added tests
    • Added a test to confirm that the existing behavior remains intact.
    • Also added a test for cases where the am/pm translations are undefined.
      • Since our application operates in non-English locales and always includes the 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?

  • Set options.fetch(:format, :administrate_datetime_default) as the default format value
    • This way, we avoid modifying the :default format used in the main application outside of the Administrate panel.
    • Currently, the Time format is fixed as "%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.
  • To use different formats in index and show views, I’d like to allow the format option to be passed into public methods.
    • In the index view, this would allow using field.time(format: :administrate_time_short), while in the show view, simply calling field.time would apply :administrate_time_default.

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.

1 participant