@formatjs/intl-datetimeformat 1.2.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/core.d.ts +7 -0
  3. package/dist/core.d.ts.map +1 -1
  4. package/dist/core.js +14 -27
  5. package/dist/core.js.map +1 -1
  6. package/dist/polyfill-with-locales-for-test262.min.js +19 -34
  7. package/dist/polyfill-with-locales-for-test262.min.js.map +1 -1
  8. package/dist/polyfill.js +35 -5
  9. package/dist/polyfill.js.map +1 -1
  10. package/dist/to_locale_string.d.ts +9 -0
  11. package/dist/to_locale_string.d.ts.map +1 -0
  12. package/dist/to_locale_string.js +24 -0
  13. package/dist/to_locale_string.js.map +1 -0
  14. package/dist/umd/intl-datetimeformat.js +14 -27
  15. package/dist/umd/intl-datetimeformat.js.map +1 -1
  16. package/dist/umd/intl-datetimeformat.min.js +1 -1
  17. package/dist/umd/intl-datetimeformat.min.js.map +1 -1
  18. package/dist/umd/polyfill.js +61 -32
  19. package/dist/umd/polyfill.js.map +1 -1
  20. package/lib/core.d.ts +7 -0
  21. package/lib/core.d.ts.map +1 -1
  22. package/lib/core.js +14 -28
  23. package/lib/core.js.map +1 -1
  24. package/lib/intl-datetimeformat.d.ts +8 -0
  25. package/lib/polyfill.js +35 -5
  26. package/lib/polyfill.js.map +1 -1
  27. package/lib/to_locale_string.d.ts +9 -0
  28. package/lib/to_locale_string.d.ts.map +1 -0
  29. package/lib/to_locale_string.js +19 -0
  30. package/lib/to_locale_string.js.map +1 -0
  31. package/lib/tsdoc-metadata.json +1 -1
  32. package/package.json +7 -6
  33. package/src/core.ts +15 -28
  34. package/src/polyfill.ts +48 -5
  35. package/src/to_locale_string.ts +40 -0
  36. package/dist/tsdoc-metadata.json +0 -11
  37. package/dist/umd/polyfill-with-locales.js +0 -1645
  38. package/dist/umd/polyfill-with-locales.js.map +0 -1
@@ -1335,6 +1335,15 @@
1335
1335
  return partitionDateTimePattern(dtf, x);
1336
1336
  }
1337
1337
  var MS_PER_DAY = 86400000;
1338
+ /**
1339
+ * https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
1340
+ * @param x
1341
+ * @param y
1342
+ * @return k of the same sign as y
1343
+ */
1344
+ function mod(x, y) {
1345
+ return x - Math.floor(x / y) * y;
1346
+ }
1338
1347
  /**
1339
1348
  * https://tc39.es/ecma262/#eqn-Day
1340
1349
  * @param t
@@ -1347,7 +1356,7 @@
1347
1356
  * @param t
1348
1357
  */
1349
1358
  function weekDay(t) {
1350
- return (day(t) + 4) % 7;
1359
+ return mod(day(t) + 4, 7);
1351
1360
  }
1352
1361
  function dayFromYear(y) {
1353
1362
  return (365 * (y - 1970) +
@@ -1474,36 +1483,13 @@
1474
1483
  var MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
1475
1484
  var MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
1476
1485
  function hourFromTime(t) {
1477
- var hour = Math.floor(t / MS_PER_HOUR) % HOURS_PER_DAY;
1478
- // Technically mod should return positive if y is positive
1479
- // per https://tc39.es/ecma262/#eqn-modulo but it doesn't...
1480
- if (objectIs(hour, -0)) {
1481
- return 0;
1482
- }
1483
- if (hour < 0) {
1484
- return 24 + hour;
1485
- }
1486
- return hour;
1486
+ return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
1487
1487
  }
1488
1488
  function minFromTime(t) {
1489
- var mins = Math.floor(t / MS_PER_MINUTE) % MINUTES_PER_HOUR;
1490
- if (objectIs(mins, -0)) {
1491
- return 0;
1492
- }
1493
- if (mins < 0) {
1494
- return 60 + mins;
1495
- }
1496
- return mins;
1489
+ return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
1497
1490
  }
1498
1491
  function secFromTime(t) {
1499
- var secs = Math.floor(t / MS_PER_SECOND) % SECONDS_PER_MINUTE;
1500
- if (objectIs(secs, -0)) {
1501
- return 0;
1502
- }
1503
- if (secs < 0) {
1504
- return 60 + secs;
1505
- }
1506
- return secs;
1492
+ return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
1507
1493
  }
1508
1494
  function getApplicableZoneData(t, timeZone) {
1509
1495
  var tzData = DateTimeFormat.tzData;
@@ -1658,15 +1644,58 @@
1658
1644
  // Meta fix so we're test262-compliant, not important
1659
1645
  }
1660
1646
 
1661
- function supportsDateStyle() {
1662
- return !!new Intl.DateTimeFormat(undefined, {
1663
- dateStyle: 'short',
1664
- }).resolvedOptions().dateStyle;
1647
+ // eslint-disable-next-line import/no-cycle
1648
+ /**
1649
+ * Number.prototype.toLocaleString ponyfill
1650
+ * https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
1651
+ */
1652
+ function toLocaleString(x, locales, options) {
1653
+ var dtf = new DateTimeFormat(locales, options);
1654
+ return dtf.format(x);
1655
+ }
1656
+ function toLocaleTimeString(x, locales, options) {
1657
+ var dtf = new DateTimeFormat(locales, toDateTimeOptions(options, 'time', 'time'));
1658
+ return dtf.format(x);
1659
+ }
1660
+
1661
+ // function supportsDateStyle() {
1662
+ // return !!(new Intl.DateTimeFormat(undefined, {
1663
+ // dateStyle: 'short',
1664
+ // } as any).resolvedOptions() as any).dateStyle;
1665
+ // }
1666
+ /**
1667
+ * https://bugs.chromium.org/p/chromium/issues/detail?id=865351
1668
+ */
1669
+ function hasChromeLt71Bug() {
1670
+ return (new Intl.DateTimeFormat('en', {
1671
+ hourCycle: 'h11',
1672
+ hour: 'numeric',
1673
+ }).formatToParts(0)[2].type !== 'dayPeriod');
1665
1674
  }
1666
1675
  if (!('DateTimeFormat' in Intl) ||
1667
1676
  !('formatToParts' in Intl.DateTimeFormat.prototype) ||
1668
- !supportsDateStyle()) {
1677
+ hasChromeLt71Bug()
1678
+ // !supportsDateStyle()
1679
+ ) {
1669
1680
  defineProperty(Intl, 'DateTimeFormat', { value: DateTimeFormat });
1681
+ defineProperty(Date.prototype, 'toLocaleString', {
1682
+ value: function toLocaleString$1(locales, options) {
1683
+ return toLocaleString(this, locales, options);
1684
+ },
1685
+ });
1686
+ // defineProperty(Date.prototype, 'toLocaleDateString', {
1687
+ // value: function toLocaleDateString(
1688
+ // locales?: string | string[],
1689
+ // options?: DateTimeFormatOptions
1690
+ // ) {
1691
+ // return _toLocaleDateString(this, locales, options);
1692
+ // },
1693
+ // });
1694
+ defineProperty(Date.prototype, 'toLocaleTimeString', {
1695
+ value: function toLocaleTimeString$1(locales, options) {
1696
+ return toLocaleTimeString(this, locales, options);
1697
+ },
1698
+ });
1670
1699
  }
1671
1700
 
1672
1701
  })));