@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.
- package/CHANGELOG.md +45 -0
- package/dist/core.d.ts +7 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +14 -27
- package/dist/core.js.map +1 -1
- package/dist/polyfill-with-locales-for-test262.min.js +19 -34
- package/dist/polyfill-with-locales-for-test262.min.js.map +1 -1
- package/dist/polyfill.js +35 -5
- package/dist/polyfill.js.map +1 -1
- package/dist/to_locale_string.d.ts +9 -0
- package/dist/to_locale_string.d.ts.map +1 -0
- package/dist/to_locale_string.js +24 -0
- package/dist/to_locale_string.js.map +1 -0
- package/dist/umd/intl-datetimeformat.js +14 -27
- package/dist/umd/intl-datetimeformat.js.map +1 -1
- package/dist/umd/intl-datetimeformat.min.js +1 -1
- package/dist/umd/intl-datetimeformat.min.js.map +1 -1
- package/dist/umd/polyfill.js +61 -32
- package/dist/umd/polyfill.js.map +1 -1
- package/lib/core.d.ts +7 -0
- package/lib/core.d.ts.map +1 -1
- package/lib/core.js +14 -28
- package/lib/core.js.map +1 -1
- package/lib/intl-datetimeformat.d.ts +8 -0
- package/lib/polyfill.js +35 -5
- package/lib/polyfill.js.map +1 -1
- package/lib/to_locale_string.d.ts +9 -0
- package/lib/to_locale_string.d.ts.map +1 -0
- package/lib/to_locale_string.js +19 -0
- package/lib/to_locale_string.js.map +1 -0
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +7 -6
- package/src/core.ts +15 -28
- package/src/polyfill.ts +48 -5
- package/src/to_locale_string.ts +40 -0
- package/dist/tsdoc-metadata.json +0 -11
- package/dist/umd/polyfill-with-locales.js +0 -1645
- package/dist/umd/polyfill-with-locales.js.map +0 -1
package/dist/polyfill.js
CHANGED
|
@@ -2,14 +2,44 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var _1 = require(".");
|
|
4
4
|
var intl_utils_1 = require("@formatjs/intl-utils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
var to_locale_string_1 = require("./to_locale_string");
|
|
6
|
+
// function supportsDateStyle() {
|
|
7
|
+
// return !!(new Intl.DateTimeFormat(undefined, {
|
|
8
|
+
// dateStyle: 'short',
|
|
9
|
+
// } as any).resolvedOptions() as any).dateStyle;
|
|
10
|
+
// }
|
|
11
|
+
/**
|
|
12
|
+
* https://bugs.chromium.org/p/chromium/issues/detail?id=865351
|
|
13
|
+
*/
|
|
14
|
+
function hasChromeLt71Bug() {
|
|
15
|
+
return (new Intl.DateTimeFormat('en', {
|
|
16
|
+
hourCycle: 'h11',
|
|
17
|
+
hour: 'numeric',
|
|
18
|
+
}).formatToParts(0)[2].type !== 'dayPeriod');
|
|
9
19
|
}
|
|
10
20
|
if (!('DateTimeFormat' in Intl) ||
|
|
11
21
|
!('formatToParts' in Intl.DateTimeFormat.prototype) ||
|
|
12
|
-
|
|
22
|
+
hasChromeLt71Bug()
|
|
23
|
+
// !supportsDateStyle()
|
|
24
|
+
) {
|
|
13
25
|
intl_utils_1.defineProperty(Intl, 'DateTimeFormat', { value: _1.DateTimeFormat });
|
|
26
|
+
intl_utils_1.defineProperty(Date.prototype, 'toLocaleString', {
|
|
27
|
+
value: function toLocaleString(locales, options) {
|
|
28
|
+
return to_locale_string_1.toLocaleString(this, locales, options);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
// defineProperty(Date.prototype, 'toLocaleDateString', {
|
|
32
|
+
// value: function toLocaleDateString(
|
|
33
|
+
// locales?: string | string[],
|
|
34
|
+
// options?: DateTimeFormatOptions
|
|
35
|
+
// ) {
|
|
36
|
+
// return _toLocaleDateString(this, locales, options);
|
|
37
|
+
// },
|
|
38
|
+
// });
|
|
39
|
+
intl_utils_1.defineProperty(Date.prototype, 'toLocaleTimeString', {
|
|
40
|
+
value: function toLocaleTimeString(locales, options) {
|
|
41
|
+
return to_locale_string_1.toLocaleTimeString(this, locales, options);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
14
44
|
}
|
|
15
45
|
//# sourceMappingURL=polyfill.js.map
|
package/dist/polyfill.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":";;AAAA,sBAAiC;AACjC,mDAAoD;AAEpD,SAAS,
|
|
1
|
+
{"version":3,"file":"polyfill.js","sourceRoot":"","sources":["../src/polyfill.ts"],"names":[],"mappings":";;AAAA,sBAAiC;AACjC,mDAAoD;AAEpD,uDAI4B;AAE5B,iCAAiC;AACjC,mDAAmD;AACnD,0BAA0B;AAC1B,mDAAmD;AACnD,IAAI;AAEJ;;GAEG;AACH,SAAS,gBAAgB;IACvB,OAAO,CACL,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE;QAC5B,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,SAAS;KACT,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CACnD,CAAC;AACJ,CAAC;AAED,IACE,CAAC,CAAC,gBAAgB,IAAI,IAAI,CAAC;IAC3B,CAAC,CAAC,eAAe,IAAI,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC;IACnD,gBAAgB,EAAE;AAClB,uBAAuB;EACvB;IACA,2BAAc,CAAC,IAAI,EAAE,gBAAgB,EAAE,EAAC,KAAK,EAAE,iBAAc,EAAC,CAAC,CAAC;IAChE,2BAAc,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,EAAE;QAC/C,KAAK,EAAE,SAAS,cAAc,CAC5B,OAA2B,EAC3B,OAA+B;YAE/B,OAAO,iCAAe,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;KACF,CAAC,CAAC;IACH,yDAAyD;IACzD,wCAAwC;IACxC,mCAAmC;IACnC,sCAAsC;IACtC,QAAQ;IACR,0DAA0D;IAC1D,OAAO;IACP,MAAM;IACN,2BAAc,CAAC,IAAI,CAAC,SAAS,EAAE,oBAAoB,EAAE;QACnD,KAAK,EAAE,SAAS,kBAAkB,CAChC,OAA2B,EAC3B,OAA+B;YAE/B,OAAO,qCAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QACrD,CAAC;KACF,CAAC,CAAC;CACJ"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DateTimeFormatOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Number.prototype.toLocaleString ponyfill
|
|
4
|
+
* https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
|
|
5
|
+
*/
|
|
6
|
+
export declare function toLocaleString(x?: Date | number, locales?: string | string[], options?: DateTimeFormatOptions): string;
|
|
7
|
+
export declare function toLocaleDateString(x?: Date | number, locales?: string | string[], options?: DateTimeFormatOptions): string;
|
|
8
|
+
export declare function toLocaleTimeString(x?: Date | number, locales?: string | string[], options?: DateTimeFormatOptions): string;
|
|
9
|
+
//# sourceMappingURL=to_locale_string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to_locale_string.d.ts","sourceRoot":"","sources":["../src/to_locale_string.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,qBAAqB,EAAC,MAAM,SAAS,CAAC;AAE9C;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,CAGR;AAED,wBAAgB,kBAAkB,CAChC,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,CAMR;AAED,wBAAgB,kBAAkB,CAChC,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,EACjB,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,MAAM,CAMR"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// eslint-disable-next-line import/no-cycle
|
|
4
|
+
var core_1 = require("./core");
|
|
5
|
+
/**
|
|
6
|
+
* Number.prototype.toLocaleString ponyfill
|
|
7
|
+
* https://tc39.es/ecma402/#sup-number.prototype.tolocalestring
|
|
8
|
+
*/
|
|
9
|
+
function toLocaleString(x, locales, options) {
|
|
10
|
+
var dtf = new core_1.DateTimeFormat(locales, options);
|
|
11
|
+
return dtf.format(x);
|
|
12
|
+
}
|
|
13
|
+
exports.toLocaleString = toLocaleString;
|
|
14
|
+
function toLocaleDateString(x, locales, options) {
|
|
15
|
+
var dtf = new core_1.DateTimeFormat(locales, core_1.toDateTimeOptions(options, 'date', 'date'));
|
|
16
|
+
return dtf.format(x);
|
|
17
|
+
}
|
|
18
|
+
exports.toLocaleDateString = toLocaleDateString;
|
|
19
|
+
function toLocaleTimeString(x, locales, options) {
|
|
20
|
+
var dtf = new core_1.DateTimeFormat(locales, core_1.toDateTimeOptions(options, 'time', 'time'));
|
|
21
|
+
return dtf.format(x);
|
|
22
|
+
}
|
|
23
|
+
exports.toLocaleTimeString = toLocaleTimeString;
|
|
24
|
+
//# sourceMappingURL=to_locale_string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to_locale_string.js","sourceRoot":"","sources":["../src/to_locale_string.ts"],"names":[],"mappings":";;AAAA,2CAA2C;AAC3C,+BAAyD;AAGzD;;;GAGG;AACH,SAAgB,cAAc,CAC5B,CAAiB,EACjB,OAA2B,EAC3B,OAA+B;IAE/B,IAAM,GAAG,GAAG,IAAI,qBAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACjD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAPD,wCAOC;AAED,SAAgB,kBAAkB,CAChC,CAAiB,EACjB,OAA2B,EAC3B,OAA+B;IAE/B,IAAM,GAAG,GAAG,IAAI,qBAAc,CAC5B,OAAO,EACP,wBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAC3C,CAAC;IACF,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAVD,gDAUC;AAED,SAAgB,kBAAkB,CAChC,CAAiB,EACjB,OAA2B,EAC3B,OAA+B;IAE/B,IAAM,GAAG,GAAG,IAAI,qBAAc,CAC5B,OAAO,EACP,wBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,CAC3C,CAAC;IACF,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC;AAVD,gDAUC"}
|
|
@@ -1336,6 +1336,15 @@
|
|
|
1336
1336
|
return partitionDateTimePattern(dtf, x);
|
|
1337
1337
|
}
|
|
1338
1338
|
var MS_PER_DAY = 86400000;
|
|
1339
|
+
/**
|
|
1340
|
+
* https://www.ecma-international.org/ecma-262/11.0/index.html#eqn-modulo
|
|
1341
|
+
* @param x
|
|
1342
|
+
* @param y
|
|
1343
|
+
* @return k of the same sign as y
|
|
1344
|
+
*/
|
|
1345
|
+
function mod(x, y) {
|
|
1346
|
+
return x - Math.floor(x / y) * y;
|
|
1347
|
+
}
|
|
1339
1348
|
/**
|
|
1340
1349
|
* https://tc39.es/ecma262/#eqn-Day
|
|
1341
1350
|
* @param t
|
|
@@ -1348,7 +1357,7 @@
|
|
|
1348
1357
|
* @param t
|
|
1349
1358
|
*/
|
|
1350
1359
|
function weekDay(t) {
|
|
1351
|
-
return (day(t) + 4
|
|
1360
|
+
return mod(day(t) + 4, 7);
|
|
1352
1361
|
}
|
|
1353
1362
|
function dayFromYear(y) {
|
|
1354
1363
|
return (365 * (y - 1970) +
|
|
@@ -1475,36 +1484,13 @@
|
|
|
1475
1484
|
var MS_PER_MINUTE = MS_PER_SECOND * SECONDS_PER_MINUTE;
|
|
1476
1485
|
var MS_PER_HOUR = MS_PER_MINUTE * MINUTES_PER_HOUR;
|
|
1477
1486
|
function hourFromTime(t) {
|
|
1478
|
-
|
|
1479
|
-
// Technically mod should return positive if y is positive
|
|
1480
|
-
// per https://tc39.es/ecma262/#eqn-modulo but it doesn't...
|
|
1481
|
-
if (objectIs(hour, -0)) {
|
|
1482
|
-
return 0;
|
|
1483
|
-
}
|
|
1484
|
-
if (hour < 0) {
|
|
1485
|
-
return 24 + hour;
|
|
1486
|
-
}
|
|
1487
|
-
return hour;
|
|
1487
|
+
return mod(Math.floor(t / MS_PER_HOUR), HOURS_PER_DAY);
|
|
1488
1488
|
}
|
|
1489
1489
|
function minFromTime(t) {
|
|
1490
|
-
|
|
1491
|
-
if (objectIs(mins, -0)) {
|
|
1492
|
-
return 0;
|
|
1493
|
-
}
|
|
1494
|
-
if (mins < 0) {
|
|
1495
|
-
return 60 + mins;
|
|
1496
|
-
}
|
|
1497
|
-
return mins;
|
|
1490
|
+
return mod(Math.floor(t / MS_PER_MINUTE), MINUTES_PER_HOUR);
|
|
1498
1491
|
}
|
|
1499
1492
|
function secFromTime(t) {
|
|
1500
|
-
|
|
1501
|
-
if (objectIs(secs, -0)) {
|
|
1502
|
-
return 0;
|
|
1503
|
-
}
|
|
1504
|
-
if (secs < 0) {
|
|
1505
|
-
return 60 + secs;
|
|
1506
|
-
}
|
|
1507
|
-
return secs;
|
|
1493
|
+
return mod(Math.floor(t / MS_PER_SECOND), SECONDS_PER_MINUTE);
|
|
1508
1494
|
}
|
|
1509
1495
|
function getApplicableZoneData(t, timeZone) {
|
|
1510
1496
|
var tzData = DateTimeFormat.tzData;
|
|
@@ -1662,6 +1648,7 @@
|
|
|
1662
1648
|
exports.DateTimeFormat = DateTimeFormat;
|
|
1663
1649
|
exports.basicFormatMatcherScore = basicFormatMatcherScore;
|
|
1664
1650
|
exports.bestFitFormatMatcherScore = bestFitFormatMatcherScore;
|
|
1651
|
+
exports.toDateTimeOptions = toDateTimeOptions;
|
|
1665
1652
|
|
|
1666
1653
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
1667
1654
|
|