Closed Bug 1329589 Opened 7 years ago Closed 7 years ago

[DateTimePicker] Set calendar variables for date picker using Intl.getCalendarInfo

Categories

(Toolkit :: UI Widgets, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: scottwu, Assigned: scottwu)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Bug 1287503 has made locale dependent calendar information such as first-day-of-week and weekends available. The date picker should make use of the Intl.getCalendarInfo API to improve l10n support.
Attachment #8829339 - Flags: review?(mconley)
Attachment #8829339 - Flags: review?(gandalf)
Comment on attachment 8829339 [details]
Bug 1329589 - Set calendar variables for date picker using Intl.getCalendarInfo

https://reviewboard.mozilla.org/r/106456/#review107418

::: toolkit/content/widgets/datetimepopup.xml:197
(Diff revision 1)
> +      <method name="getCalendarInfo">
> +        <parameter name="locale"/>
> +        <body><![CDATA[
> +          const l10n = {};
> +          const mozIntl = Components.classes["@mozilla.org/mozintl;1"].getService(Components.interfaces.mozIMozIntl);
> +          mozIntl.addGetCalendarInfo(l10n);

gandalf: I saw that you've used mozIntl.addGetCalendarInfo(Intl) to add the method to `Intl`, but I wonder if it's okay to mutate `Intl`?
Comment on attachment 8829339 [details]
Bug 1329589 - Set calendar variables for date picker using Intl.getCalendarInfo

https://reviewboard.mozilla.org/r/106458/#review107670

Seems okay, but see my suggestion below.

::: toolkit/content/widgets/datetimepopup.xml:192
(Diff revision 1)
> +      <method name="getCalendarInfo">
> +        <parameter name="locale"/>
> +        <body><![CDATA[
> +          const l10n = {};
> +          const mozIntl = Components.classes["@mozilla.org/mozintl;1"].getService(Components.interfaces.mozIMozIntl);
> +          mozIntl.addGetCalendarInfo(l10n);
> +          return l10n.getCalendarInfo(locale);
> +        ]]></body>
> +      </method>
> +      <method name="parseCalendarInfo">
> +        <parameter name="calendarInfo"/>

Out of curiosity, why is this split into two steps? Do we expect to call getCalendarInfo and not pass immediately to parseCalendarInfo somewhere?

If not, I'm fine with having a helper function for getting the calendar info, but perhaps we can just have callers call `getCalendarInfo(locale)` and get back what you're returning from `parseCalendarInfo`?
Attachment #8829339 - Flags: review?(mconley) → review+
Comment on attachment 8829339 [details]
Bug 1329589 - Set calendar variables for date picker using Intl.getCalendarInfo

https://reviewboard.mozilla.org/r/106458/#review107670

> Out of curiosity, why is this split into two steps? Do we expect to call getCalendarInfo and not pass immediately to parseCalendarInfo somewhere?
> 
> If not, I'm fine with having a helper function for getting the calendar info, but perhaps we can just have callers call `getCalendarInfo(locale)` and get back what you're returning from `parseCalendarInfo`?

My initial thought was to make them two functions before they do different things, but I can see that combining them makes sense because I don't expect getCalendarInfo to be used anywhere else.
Comment on attachment 8829339 [details]
Bug 1329589 - Set calendar variables for date picker using Intl.getCalendarInfo

https://reviewboard.mozilla.org/r/106458/#review107926

lgtm!
Attachment #8829339 - Flags: review?(gandalf) → review+
Thanks! Checking it in.

:gandalf, I do have a question about testing. I'm working on adding browser chrome tests in Bug 1328219, and I wonder what would be a good way test for different UI locales?
Flags: needinfo?(gandalf)
Keywords: checkin-needed
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/e4754459cae8
Set calendar variables for date picker using Intl.getCalendarInfo r=gandalf,mconley
Keywords: checkin-needed
You can't do too much. As a rule of thumb, try to write tests that do not rely on any particular values returned from intl functions.

Where you do need some bits, test for 2 locales that have different values, maybe 'de' and 'ar'?
This would cover you for bidi and l10n.
Flags: needinfo?(gandalf)
https://hg.mozilla.org/mozilla-central/rev/e4754459cae8
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: