Formats JavaScript dates to relative time strings (e.g., "3 hours ago").
This minor release upgrades the locale data to CLDR 28 and [email protected]
.
This minor release simply upgrades to [email protected]
.
This feature release fixes issues with the locale data—particularly with zh-Hant
locales (#25)—plus adds support for more locales (#28), and support for passing a "now" has been added to the format()
method (#26, @jbaudanza).
The locale data has been vastly improved in the following ways:
zh-Hant-HK
is not the same as zh-Hant
which is not the same as zh
.This release also includes improvements for how locales are resolved. Here are some details of these changes:
If no extra locale data is loaded, the locale will always resolved to en
.
If locale data is missing for a leaf locale like fr-FR
, but there is data for the root, fr
in this case, then its root will be used.
If there's data for the specified locale, then that locale will be resolved; i.e.,
var rf = new IntlRelativeFormat('en-US');
assert(rf.resolvedOptions().locale === 'en-US'); // true
The resolved locales are now normalized; e.g., en-us
will resolve to: en-US
.
now
OptionA "now" can now be passed when calling the format()
method to control what the date being formatted is relative to. Having this option improves testability, while also allowing format()
to be a pure function and not rely on a temporal global value, Date.now()
.
var now = 1425839825400;
var rf = new Intl.RelativeFormat();
rf.format(someDate, {now: now});
This patch release actually fixes the issue brought up in https://github.com/yahoo/intl-messageformat/issues/90 so that the Browserify/Webpack output is compatible with ES3 environments. The previous release had .default
s in the transpiled CommonJS modules, the es6-module-transpiler
has been updated to fix that, and this release contains those fixes.
This patch release fixes the issue brought up in https://github.com/yahoo/intl-messageformat/issues/90 so that the Browserify/Webpack output is compatible with ES3 environments. Source maps for .min.js
files have also been fixed so that they now include the actual source code.
This patch release improves support for using Browserify or Webpack to bundle intl-relativeformat
. Since the context of these tools is to bundle for the browser, this release will only include the English locale data in the bundle by default. (Previously the data for all locales would be included when bundling with Browserify or Webpack.)
When you need to support another locale in your app and you're using Browserify or Webpack, we recommend the following approach:
// app.js
var IntlRelativeFormat = window.IntlRelativeFormat = require('intl-relativeformat');
// ...
<script src="/app.bundle.js"></script>
<script src="/intl-relativeformat/dist/locale-data/fr.js"></script>
This will expose IntlRelativeFormat
as a global object in the browser, allowing you to load the script for the locale data you need for the page or current request.
locales
ValueFixed issue #17 where the original locales
value the user passed to the IntlRelativeFormat
constructor was not being propagated to the internal IntlMessageFormat
instances. Instead, only the resolved root locale was being propagated. This issue would arise when using the Intl.js polyfill.
This release also includes improvements to source maps, making debugging easier.
Intl-relativeformat aims to provide a way to format different variations of relative time. You can use this package in the browser and on the server via Node.js.
This implementation is very similar to moment.js, in concept, although it provides only formatting features based on the Unicode CLDR locale data, an industry standard that supports more than 150 locales.