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

Add format option to time field #2029

Merged
merged 1 commit into from
Sep 24, 2021
Merged

Add format option to time field #2029

merged 1 commit into from
Sep 24, 2021

Conversation

amymariewall
Copy link
Contributor

@amymariewall amymariewall commented Aug 5, 2021

Previously there was no way to specify format for a time field, but you can specify a format for date and datetime fields. This commit adds the ability to pass a format option to time fields.

Because I18n uses the time locale key for for all objects with a time, retain the hard-coded time field format where no format option is passed to avoid a breaking change.

Addresses #1227.

Copy link
Collaborator

@pablobm pablobm left a comment

Choose a reason for hiding this comment

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

Looking good! Do you think you'll be able to sort the Hound warnings and those with_translations comments?

@tjvc tjvc force-pushed the add-format-to-time branch 2 times, most recently from cfbe6a7 to 105383f Compare September 10, 2021 18:24
@tjvc tjvc changed the title [WIP] Adds format to time Add format option to time field Sep 10, 2021
@tjvc
Copy link
Contributor

tjvc commented Sep 10, 2021

@pablobm @amymariewall I think this is ready for another review. I've addressed the linter errors and another issue I spotted: because I18n uses the same key in the locales file for all objects with a time (time), we cannot set separate default formats for our time and datetime fields. I've resolved this by applying a hard-coded format to the time field where a format option is not passed (as we were previously) so as not to introduce a breaking change, but definitely open to other ideas here!

@tjvc tjvc marked this pull request as ready for review September 10, 2021 18:39
@tjvc tjvc requested a review from pablobm September 17, 2021 08:11
Copy link
Member

@nickcharlton nickcharlton left a comment

Choose a reason for hiding this comment

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

I think this looks good; just one comment about use of let.

formats: { short: "%H:%M" },
},
}
end
Copy link
Member

Choose a reason for hiding this comment

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

A minor point: we typically avoid using let in this codebase and prefer to either inline a variable in each it or extract it into a normal Ruby method.

@tjvc tjvc requested a review from nickcharlton September 24, 2021 08:39
Copy link
Member

@nickcharlton nickcharlton left a comment

Choose a reason for hiding this comment

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

One more comment; if you change that, feel free to merge it whenever!

describe "#time" do
before do
@time = DateTime.new(2021, 3, 26, 16, 38)
end
Copy link
Member

Choose a reason for hiding this comment

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

And before! I'd just put the DateTime definition in each it block.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I totally missed the second part of your original comment! 🤦‍♂️

Previously there was no way to specify format for a time field, but you
can specify a format for date and datetime fields. This commit adds the
ability to pass a format option to time fields.

Because I18n uses the time locale key for for all objects with a time
[0], retain the hard-coded time field format where no format option is
passed to avoid a breaking change.

Addresses issue #1227.

[0] https://github.com/ruby-i18n/i18n/blob/0888807ab2fe4f4c8a4b780f5654a8175df61feb/lib/i18n/backend/base.rb#L82

Co-authored-by: Thom Carter <thom.carter@thoughtbot.com>
@tjvc tjvc force-pushed the add-format-to-time branch from 93fc827 to 55843cc Compare September 24, 2021 11:01
@tjvc tjvc merged commit f8c0d71 into main Sep 24, 2021
@tjvc tjvc deleted the add-format-to-time branch September 24, 2021 11:13
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.

4 participants