Closed Bug 1208698 Opened 9 years ago Closed 9 years ago

Extend mozIntl with RelativeTimeFormat and date.*

Categories

(Firefox OS Graveyard :: Gaia::L10n, defect)

ARM
Gonk (Firefox OS)
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: zbraniecki, Unassigned)

References

Details

Attachments

(1 file)

I was planning to keep mozL10n.DateTimeFormat().prettyNow and mozL10n.DateTimeFormat().relativeParts in l10n_date for now, but today I encountered bugs in it that triggered me to rewrite it into mozIntl.

This is the last couple of functions that are used from l10n_date, so once we land this, we'll be able to move everything away from l10n_date to mozIntl and remove that file.
Comment on attachment 8666307 [details] [review]
[gaia] zbraniecki:1208698-extend-mozintl-with-relativetime > mozilla-b2g:master

Stas,

I ported shared/js/l10n_date.js relativeDate and relativeParts to

mozIntl._gaia.relativeParts and mozIntl._gaia.relativeDate.

I also added a shim of Intl.RelativeTimeFormat and switched relativeDate to use it.

It's not perfect, but it covers all tests that I was able to write and all tests that I ported from l10n_date.js testsuite.

I'd like to land it and be able to move everything away from l10n_date.js and remove it soon.
Attachment #8666307 - Flags: review?(stas)
I decided to extend this patch to add all changes that I found necessary while working on:
 - migrate System/Callscreen to mozIntl (bug 1208806)
 - migrate Email to mozIntl (bug 1208889)
 - migrate Calendar to mozIntl (bug 1206318)
 - prepare Video for L10n API v3 (bug 1197454)
 - prepare Clock for L10n API v3 (bug 1207044)

Major changes:
* intlHelper
  * support for mozdatetime and mozduration from mozIntl
  * move observers to reset on languagechange, but fireObservers on DOMLocalized
  * introduce minimal mock_intl_helper
  * improve tests
* mozIntl
  * introduce minimal mock_moz_intl
  * DateTimeFormat
    * improve support for removing dayperiod when timezone is broken (temporary, see bug 1208808)
    * add DateTimeFormat().resolvedOptions() matching Intl API's one
  * scalable DurationFormat 
  * introduce RelativeTimeFormat based on https://rawgit.com/caridy/intl-relative-time-spec/master/index.html
  * port l10n_date.js to mozIntl
    * relativePart is a port of mozL10n.DateTimeFormat().relativeParts that return just one token (using RelativeTimeFormat algorithm)
    * relativeDate is a port of mozL10n.DateTimeFormat().fromNow|relativeDate that uses RelativeTimeFormat
  * improve tests including porting all tests from l10n_date_test.js
  * add missing date.properties entries

The mozIntl._gaia functions are direct conversions from l10n_date, to make it easier to port apps to them. We may later reorganize this, currently my goal was to introduce RelativeTimeFormat and move l10n_date to use it.

I was slowly accruing this code in multiple patches and I decided to converge all of them into this patch since I need your review on all of those pieces anyway.
Comment on attachment 8666307 [details] [review]
[gaia] zbraniecki:1208698-extend-mozintl-with-relativetime > mozilla-b2g:master

This looks good to me, but I'm not clear on the type of date .format() expects.  In one comment on gh you said it was supposed to be a Date object, but in tests and in other place you seem to pass integers.  Is that for backwards-compatibility with l10n_date?
Attachment #8666307 - Flags: review?(stas) → review+
No, I was just wrong. It seems that all Intl formatters take Date object or an integer, because the first operation is to cast it with `new Date(param);` which can take integer or Date object.
Thanks :stas for a quick review!

Commit: https://github.com/mozilla-b2g/gaia/commit/da60421d6a006b56f9de8dae7c928e20a4a3808c
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: