Migrate mozIntl.DateTimeFormat to Intl.DateTimeFormat.formatToParts

RESOLVED FIXED

Status

RESOLVED FIXED
3 years ago
3 years ago

People

(Reporter: gandalf, Assigned: gandalf)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 years ago
Since we now have DateTimeFormat.prototype.formatToParts in Gecko, we should migrate Gaia to use it and remove mozIntl.DateTimeFormat.
Created attachment 8728620 [details] [review]
[gaia] zbraniecki:1255110-migrate-to-formattoparts > mozilla-b2g:master
(Assignee)

Comment 2

3 years ago
Comment on attachment 8728620 [details] [review]
[gaia] zbraniecki:1255110-migrate-to-formattoparts > mozilla-b2g:master

Stas, can you review this for me?
Attachment #8728620 - Flags: review?(stas)
(Assignee)

Updated

3 years ago
Assignee: nobody → gandalf
Comment on attachment 8728620 [details] [review]
[gaia] zbraniecki:1255110-migrate-to-formattoparts > mozilla-b2g:master

LGTM, thanks, Zibi!

Just a nit about Array.reduce:  you may want to change:

  .reduce((string, part) => string + part, '');

to the equivalent:

  .reduce((string, part) => string + part);
Attachment #8728620 - Flags: review?(stas) → review+
(Assignee)

Comment 4

3 years ago
Unfortunately, I cannot do that.

formatToParts may return an empty array and in that case, reduce will error because original string is undefined.

In order cover that scenario, we need the second argument on reduce to be an empty string.
(Assignee)

Comment 5

3 years ago
Commit: https://github.com/mozilla-b2g/gaia/commit/175c2f208c92a9ebdef943715621cdac2bda81c1
Status: NEW → RESOLVED
Last Resolved: 3 years ago
Resolution: --- → FIXED
(In reply to Zibi Braniecki [:gandalf][:zibi] from comment #4)
> Unfortunately, I cannot do that.
> 
> formatToParts may return an empty array and in that case, reduce will error
> because original string is undefined.

Ah, I didn't realize this was possible, thanks!  Out of curiosity, in what cases would formatToParts return an empty array?
(Assignee)

Comment 7

3 years ago
When Intl can't find a matching pattern in selected language. Each language may have different coverage of patterns (although at the moment I think that's rare). 

An example combo that works in the current Firefox is:

(new Date()).toLocaleString('en-US', {era: 'long', day: '2-digit'});
Ey :gandalf! It seems that GU3 started failing after this commit:

TEST-UNEXPECTED-FAIL | null | [calendar-test/unit/views/current_time_test.js] Views.CurrentTime #_render should update position and time
TypeError: formatter.formatToParts is not a function 

Is there anything missing in the test? Thanks!
Flags: needinfo?(gandalf)
(Assignee)

Comment 9

3 years ago
Yeah! Thank you for finding it!

Fixed: https://github.com/mozilla-b2g/gaia/commit/355baa0efee94e9c6f7aea4b3935060753831d01
Flags: needinfo?(gandalf)
You need to log in before you can comment on or make changes to this bug.