@js-joda/locale 4.0.0 → 4.2.1

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 (54) hide show
  1. package/.babelrc +15 -9
  2. package/CHANGELOG.md +20 -2
  3. package/README.md +11 -10
  4. package/dist/js-joda-locale.d.ts +7 -0
  5. package/dist/js-joda-locale.js +207 -158
  6. package/dist/js-joda-locale.js.map +1 -1
  7. package/dist/js-joda-locale.min.js +19 -13
  8. package/dist/prebuilt/de/index.js +231 -175
  9. package/dist/prebuilt/de/index.js.map +1 -1
  10. package/dist/prebuilt/de-de/index.js +231 -175
  11. package/dist/prebuilt/de-de/index.js.map +1 -1
  12. package/dist/prebuilt/en/index.js +231 -175
  13. package/dist/prebuilt/en/index.js.map +1 -1
  14. package/dist/prebuilt/en-us/index.js +231 -175
  15. package/dist/prebuilt/en-us/index.js.map +1 -1
  16. package/dist/prebuilt/es/index.js +231 -175
  17. package/dist/prebuilt/es/index.js.map +1 -1
  18. package/dist/prebuilt/fr/index.js +231 -175
  19. package/dist/prebuilt/fr/index.js.map +1 -1
  20. package/dist/prebuilt/fr-fr/index.js +231 -175
  21. package/dist/prebuilt/fr-fr/index.js.map +1 -1
  22. package/dist/prebuilt/hi/index.js +231 -175
  23. package/dist/prebuilt/hi/index.js.map +1 -1
  24. package/dist/prebuilt/it/index.js +231 -175
  25. package/dist/prebuilt/it/index.js.map +1 -1
  26. package/dist/prebuilt/it-it/index.js +231 -175
  27. package/dist/prebuilt/it-it/index.js.map +1 -1
  28. package/dist/prebuilt/ja/index.js +231 -175
  29. package/dist/prebuilt/ja/index.js.map +1 -1
  30. package/dist/prebuilt/ja-jp/index.js +231 -175
  31. package/dist/prebuilt/ja-jp/index.js.map +1 -1
  32. package/dist/prebuilt/ko/index.js +231 -175
  33. package/dist/prebuilt/ko/index.js.map +1 -1
  34. package/dist/prebuilt/ro/index.js +231 -175
  35. package/dist/prebuilt/ro/index.js.map +1 -1
  36. package/dist/prebuilt/sv/index.js +231 -175
  37. package/dist/prebuilt/sv/index.js.map +1 -1
  38. package/dist/prebuilt/sv-se/index.js +231 -175
  39. package/dist/prebuilt/sv-se/index.js.map +1 -1
  40. package/dist/prebuilt/zh/index.js +231 -175
  41. package/dist/prebuilt/zh/index.js.map +1 -1
  42. package/examples/usage_node_build.js +2 -2
  43. package/package.json +19 -45
  44. package/src/_init.js +2 -0
  45. package/src/format/LocaleDateTimeFormatter.js +57 -1
  46. package/src/format/LocaleStore.js +4 -2
  47. package/src/format/cldr/CldrCache.js +6 -0
  48. package/src/format/cldr/CldrDateTimeFormatterBuilder.js +1 -1
  49. package/src/format/cldr/CldrDateTimeTextProvider.js +2 -2
  50. package/src/format/cldr/CldrZoneTextPrinterParser.js +23 -5
  51. package/src/plug.js +4 -0
  52. package/src/temporal/WeekFields.js +2 -2
  53. package/utils/load_cldrData.prebuilt.js +4 -1
  54. package/utils/load_cldrData.postinstall.js +0 -15
@@ -8,7 +8,7 @@ require('@js-joda/timezone');
8
8
 
9
9
  function outputDateInDifferentLocales(zdt) {
10
10
  var { Locale } = require('./build/js-joda-locale');
11
- console.log('Times in ' + zdt.zone());
11
+ console.log(`Times in ${zdt.zone()}`);
12
12
  console.log('');
13
13
  console.log('en_US formatted string:', zdt.format(joda.DateTimeFormatter.ofPattern('eeee MMMM dd yyyy GGGG, hh:mm:ss a zzzz, zz, OOOO \'Week: \' ww, \'Quarter: \' QQQ').withLocale(Locale.US)));
14
14
  console.log('en_GB formatted string:', zdt.format(joda.DateTimeFormatter.ofPattern('eeee MMMM dd yyyy GGGG, hh:mm:ss a zzzz, zz, OOOO \'Week: \' ww, \'Quarter: \' QQQ').withLocale(Locale.UK)));
@@ -27,7 +27,7 @@ try {
27
27
  var { Locale } = require('./build/js-joda-locale');
28
28
  console.log('locale', Locale);
29
29
 
30
- console.log('availableLocales:' + JSON.stringify(Locale.getAvailableLocales(), null, 4));
30
+ console.log(`availableLocales:${JSON.stringify(Locale.getAvailableLocales(), null, 4)}`);
31
31
 
32
32
  var zdt = joda.ZonedDateTime.of(2017, 1, 1, 0, 0, 0, 0, joda.ZoneId.of('Europe/Berlin'));
33
33
  outputDateInDifferentLocales(zdt);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-joda/locale",
3
- "version": "4.0.0+36.0.0",
3
+ "version": "4.2.1",
4
4
  "description": "plugin for locale functionality for js-joda",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,20 +9,21 @@
9
9
  "main": "dist/js-joda-locale.js",
10
10
  "typings": "dist/js-joda-locale.d.ts",
11
11
  "scripts": {
12
- "version": "npm run build-all",
13
- "test": "./node_modules/.bin/mocha --timeout 5000 --require @babel/register ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js test/pluginTest_mochaOnly.js",
14
- "test-coverage": "NODE_ENV=test COVERAGE=1 ../../node_modules/.bin/nyc --report-dir=build/coverage --reporter=lcov --reporter html ./node_modules/.bin/mocha --timeout 5000 --require @babel/register --reporter progress ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
15
- "test-browser": "./node_modules/.bin/karma start --reporters=dots --single-run",
16
- "test-saucelabs": "./node_modules/.bin/karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_ie,sl_firefox,sl_ios_simulator\" --single-run=true",
12
+ "version": "npm run build-locale-dist",
13
+ "test": "npx mocha --timeout 5000 --require @babel/register ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js test/pluginTest_mochaOnly.js",
14
+ "test-coverage": "NODE_ENV=test COVERAGE=1 npx nyc --report-dir=build/coverage --reporter=lcov --reporter html npx mocha --timeout 5000 --require @babel/register --reporter progress ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
15
+ "test-browser": "npx karma start --reporters=dots --single-run",
16
+ "test-saucelabs": "npx karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_ie,sl_firefox,sl_ios_simulator\" --single-run=true",
17
17
  "test-ts-definitions": "tsc -p test/typescript_definitions",
18
- "build-dist-es5": "./node_modules/.bin/babel src -d build/es5",
19
- "build-dist": "./node_modules/.bin/webpack --progress --colors --bail && DIST_MIN=1 ./node_modules/.bin/webpack --progress --colors --bail",
18
+ "test-ci": "npm run build-dist && npm run test && npm run test-browser && npm run test-ts-definitions && npm run test-coverage",
19
+ "build-dist-es5": "npx babel src -d build/es5",
20
+ "build-dist": "npx webpack --progress --colors --bail && DIST_MIN=1 npx webpack --progress --colors --bail",
20
21
  "build-examples": "node ./utils/build_package.js -o examples/build/js-joda-locale -m node_modules -c utils/load_cldrData.prebuilt.js -l \"en.*\" de fr es zh hi ru",
21
22
  "build-prebuilt": "rm -rf dist/prebuilt/*;node utils/build_package.js --config build_package.prebuilt.json",
22
23
  "build_package": "node ./utils/build_package.js",
23
- "build-all": "npm run build-dist-es5 && npm run build-dist && npm run build-examples && npm run build-prebuilt && npm run create-packages",
24
+ "build-locale-dist": "npm run build-dist-es5 && npm run build-dist && npm run build-examples && npm run build-prebuilt && npm run create-packages",
24
25
  "create-packages": "rm -rf packages/*;node utils/create_packages.js --config build_package.prebuilt.json",
25
- "lint": "../../node_modules/.bin/eslint ."
26
+ "lint": "npx eslint ."
26
27
  },
27
28
  "keywords": [
28
29
  "date",
@@ -47,45 +48,18 @@
47
48
  },
48
49
  "homepage": "https://github.com/js-joda/js-joda-locale#readme",
49
50
  "peerDependencies": {
50
- "cldr-data": "*",
51
- "cldrjs": "^0.5.4",
52
51
  "@js-joda/core": ">=3.2.0",
53
- "@js-joda/timezone": "^2.3.0"
52
+ "@js-joda/timezone": "^2.3.0",
53
+ "cldr-data": "*",
54
+ "cldrjs": "^0.5.4"
54
55
  },
55
56
  "devDependencies": {
56
- "@babel/cli": "^7.14.8",
57
- "@babel/core": "^7.7.4",
58
- "@babel/polyfill": "^7.7.0",
59
- "@babel/preset-env": "^7.7.4",
60
- "@babel/register": "^7.7.4",
61
- "@js-joda/core": ">=1.11.0",
62
- "@js-joda/timezone": "^2.2.0",
63
- "babel-loader": "^8.0.6",
64
- "babel-plugin-add-module-exports": "^1.0.2",
65
- "babel-plugin-istanbul": "^5.2.0",
66
- "chai": "^4.2.0",
57
+ "@js-joda/core": "^4.2.1",
58
+ "@js-joda/timezone": "^2.7.1",
67
59
  "cldr-data": "^36.0.0",
68
- "cldrjs": "^0.5.1",
69
- "coveralls": "^3.1.1",
70
- "karma": "^4.4.1",
71
- "karma-chai-plugins": "^0.9.0",
72
- "karma-chrome-launcher": "^3.1.0",
73
- "karma-firefox-launcher": "^1.2.0",
74
- "karma-mocha": "^1.3.0",
75
- "karma-phantomjs-launcher": "^1.0.4",
76
- "karma-sauce-launcher": "^2.0.2",
77
- "karma-sourcemap-loader": "^0.3.7",
78
- "karma-webpack": "^4.0.2",
79
- "mocha": "^6.2.2",
80
- "phantomjs-prebuilt": "^2.1.16",
81
- "requirejs": "^2.3.6",
82
- "requirejs-json": "0.0.3",
83
- "requirejs-text": "^2.0.15",
84
- "typescript": "^3.7.5",
85
- "webpack": "^4.41.2",
86
- "webpack-cli": "^3.3.10",
87
- "yargs": "^15.0.2"
60
+ "cldrjs": "^0.5.5"
88
61
  },
89
62
  "cldr-data-coverage": "core",
90
- "cldr-data-urls-filter": "(cldr-core|cldr-numbers-modern|cldr-dates-modern)"
63
+ "cldr-data-urls-filter": "(cldr-core|cldr-numbers-modern|cldr-dates-modern)",
64
+ "gitHead": "485c4b2be852563615e2d2a8c3f0bca22d86bcd4"
91
65
  }
package/src/_init.js CHANGED
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { _init as localeInit } from './Locale';
7
7
  import { _init as weekFieldsInit } from './temporal/WeekFields';
8
+ import { _init as dateTimeFormatterInit } from './format/LocaleDateTimeFormatter';
8
9
 
9
10
  let isInit = false;
10
11
 
@@ -18,6 +19,7 @@ function init() {
18
19
 
19
20
  localeInit();
20
21
  weekFieldsInit();
22
+ dateTimeFormatterInit();
21
23
  }
22
24
 
23
25
  init();
@@ -3,9 +3,16 @@
3
3
  * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
4
4
  */
5
5
 
6
- import { _ as jodaInternal, DateTimeFormatter } from '@js-joda/core';
6
+ import {
7
+ _ as jodaInternal,
8
+ DateTimeFormatter,
9
+ ChronoField,
10
+ ResolverStyle,
11
+ IsoChronology,
12
+ } from '@js-joda/core';
7
13
  // eslint-disable-next-line no-unused-vars
8
14
  import Locale from '../Locale';
15
+ import CldrDateTimeFormatterBuilder from './cldr/CldrDateTimeFormatterBuilder';
9
16
 
10
17
  const { assert: { requireNonNull } } = jodaInternal;
11
18
 
@@ -29,6 +36,55 @@ export default class LocaleDateTimeFormatter extends DateTimeFormatter {
29
36
  }
30
37
  return new DateTimeFormatter(this._printerParser, locale, this._decimalStyle, this._resolverStyle, this._resolverFields, this._chrono, this._zone);
31
38
  }
39
+ }
40
+
41
+ export function _init() {
42
+ const dow = {
43
+ 1: 'Mon',
44
+ 2: 'Tue',
45
+ 3: 'Wed',
46
+ 4: 'Thu',
47
+ 5: 'Fri',
48
+ 6: 'Sat',
49
+ 7: 'Sun',
50
+ };
32
51
 
52
+ const moy = {
53
+ 1: 'Jan',
54
+ 2: 'Feb',
55
+ 3: 'Mar',
56
+ 4: 'Apr',
57
+ 5: 'May',
58
+ 6: 'Jun',
59
+ 7: 'Jul',
60
+ 8: 'Aug',
61
+ 9: 'Sep',
62
+ 10: 'Oct',
63
+ 11: 'Nov',
64
+ 12: 'Dec',
65
+ };
33
66
 
67
+ LocaleDateTimeFormatter.RFC_1123_DATE_TIME = new CldrDateTimeFormatterBuilder()
68
+ .parseCaseInsensitive()
69
+ .parseLenient()
70
+ .optionalStart()
71
+ .appendText(ChronoField.DAY_OF_WEEK, dow)
72
+ .appendLiteral(', ')
73
+ .optionalEnd()
74
+ .appendValue(ChronoField.DAY_OF_MONTH, 2)
75
+ .appendLiteral(' ')
76
+ .appendText(ChronoField.MONTH_OF_YEAR, moy)
77
+ .appendLiteral(' ')
78
+ .appendValue(ChronoField.YEAR, 4) // 2 digit year not handled
79
+ .appendLiteral(' ')
80
+ .appendValue(ChronoField.HOUR_OF_DAY, 2)
81
+ .appendLiteral(':')
82
+ .appendValue(ChronoField.MINUTE_OF_HOUR, 2)
83
+ .optionalStart()
84
+ .appendLiteral(':')
85
+ .appendValue(ChronoField.SECOND_OF_MINUTE, 2)
86
+ .optionalEnd()
87
+ .appendLiteral(' ')
88
+ .appendZoneId()
89
+ .toFormatter(ResolverStyle.SMART).withChronology(IsoChronology.INSTANCE);
34
90
  }
@@ -5,6 +5,8 @@
5
5
 
6
6
 
7
7
  /**
8
+ * @private
9
+ *
8
10
  * Helper method to create an immutable entry.
9
11
  *
10
12
  * @param text the text, not null
@@ -16,7 +18,7 @@ export const createEntry = (text, field) => {
16
18
  key: text,
17
19
  value: field,
18
20
  toString: function () {
19
- return text + '->' + field;
21
+ return `${text}->${field}`;
20
22
  }
21
23
  };
22
24
  };
@@ -49,7 +51,7 @@ export class LocaleStore {
49
51
  Object.keys(valueTextMap[style]).forEach((key) => {
50
52
  const value = valueTextMap[style][key];
51
53
  if (reverse[value] === undefined) {
52
- reverse[value] = createEntry(value, Number.parseInt(key));
54
+ reverse[value] = createEntry(value, parseInt(key));
53
55
  list.push(reverse[value]);
54
56
  }
55
57
  });
@@ -8,6 +8,8 @@ import Cldr from 'cldrjs';
8
8
 
9
9
  const cldrDataLoaded = new Set();
10
10
  /**
11
+ * @private
12
+ *
11
13
  * Loads the Cldr data for the given path if it hasn't been loaded before.
12
14
  */
13
15
  export const loadCldrData = (path) => {
@@ -19,6 +21,8 @@ export const loadCldrData = (path) => {
19
21
 
20
22
  const localeToCldrInstanceCache = {};
21
23
  /**
24
+ * @private
25
+ *
22
26
  * Returns a Cldr instance for the given locale.
23
27
  * Memoized, so a given locale will always return the exact same cldr instance.
24
28
  */
@@ -32,6 +36,8 @@ export const getOrCreateCldrInstance = (locale) => {
32
36
 
33
37
  const localeToMapZonesCache = {};
34
38
  /**
39
+ * @private
40
+ *
35
41
  * Returns a map zones object for a Cldr instance.
36
42
  * Memoized, so for any given Cldr instance locale, the same object will be returned.
37
43
  */
@@ -16,7 +16,7 @@ import {
16
16
  import TextPrinterParser from '../parser/TextPrinterParser';
17
17
  import CldrDateTimeTextProvider from './CldrDateTimeTextProvider';
18
18
  import CldrZoneTextPrinterParser from './CldrZoneTextPrinterParser';
19
- import {LocaleStore} from '../LocaleStore';
19
+ import { LocaleStore } from '../LocaleStore';
20
20
  import LocalizedOffsetPrinterParser from '../parser/LocalizedOffsetPrinterParser';
21
21
  import WeekFieldsPrinterParser from '../parser/WeekFieldsPrinterParser';
22
22
 
@@ -7,8 +7,8 @@ import { ChronoField, IsoFields, TextStyle } from '@js-joda/core';
7
7
 
8
8
  import cldrData from 'cldr-data';
9
9
 
10
- import {LocaleStore, createEntry} from '../LocaleStore';
11
- import {getOrCreateCldrInstance, loadCldrData} from './CldrCache';
10
+ import { LocaleStore, createEntry } from '../LocaleStore';
11
+ import { getOrCreateCldrInstance, loadCldrData } from './CldrCache';
12
12
 
13
13
  /**
14
14
  * The Service Provider Implementation to obtain date-time text for a field.
@@ -12,7 +12,7 @@ import {
12
12
  ZoneRulesProvider,
13
13
  } from '@js-joda/core';
14
14
 
15
- import {getOrCreateCldrInstance, getOrCreateMapZones, loadCldrData} from './CldrCache';
15
+ import { getOrCreateCldrInstance, getOrCreateMapZones, loadCldrData } from './CldrCache';
16
16
 
17
17
  const { assert: { requireNonNull, requireInstance } } = jodaInternal;
18
18
 
@@ -27,7 +27,7 @@ const LENGTH_COMPARATOR = (str1, str2) => {
27
27
 
28
28
  /**
29
29
  * Cache for `_cachedResolveZoneIdText`.
30
- *
30
+ *
31
31
  * Its basic structure is:
32
32
  * Obj { locale: zoneId }
33
33
  * Obj { zoneId: style}
@@ -46,6 +46,7 @@ export default class CldrZoneTextPrinterParser {
46
46
  requireNonNull(textStyle, 'textStyle');
47
47
  requireInstance(textStyle, TextStyle, 'textStyle');
48
48
  this._textStyle = textStyle;
49
+ this._zoneIdsLocales = {};
49
50
  loadCldrData('supplemental/likelySubtags.json');
50
51
  loadCldrData('supplemental/metaZones.json');
51
52
  }
@@ -153,10 +154,13 @@ export default class CldrZoneTextPrinterParser {
153
154
  return true;
154
155
  }
155
156
 
156
- parse(context, text, position) {
157
+ _resolveZoneIds(localString) {
158
+ if(this._zoneIdsLocales[localString] != null) {
159
+ return this._zoneIdsLocales[localString];
160
+ }
157
161
  const ids = {};
158
- loadCldrData(`main/${context.locale().localeString()}/timeZoneNames.json`);
159
- const cldr = getOrCreateCldrInstance(context.locale().localeString());
162
+ loadCldrData(`main/${localString}/timeZoneNames.json`);
163
+ const cldr = getOrCreateCldrInstance(localString);
160
164
 
161
165
  for (const id of ZoneRulesProvider.getAvailableZoneIds()) {
162
166
  ids[id] = id;
@@ -177,6 +181,20 @@ export default class CldrZoneTextPrinterParser {
177
181
  }
178
182
  // threeten is using a (sorted) TreeMap... so we need to sort the keys
179
183
  const sortedKeys = Object.keys(ids).sort(LENGTH_COMPARATOR);
184
+
185
+ this._zoneIdsLocales[localString] = { ids, sortedKeys };
186
+ return this._zoneIdsLocales[localString];
187
+ }
188
+
189
+ // That's a very poor implementation, there are missing bug fixes and functionality from threeten and jdk
190
+ parse(context, text, position) {
191
+ for (const name of ['UTC', 'GMT']) {
192
+ if (context.subSequenceEquals(text, position, name, 0, name.length)) {
193
+ context.setParsedZone(ZoneId.of(name));
194
+ return position + name.length;
195
+ }
196
+ }
197
+ const { ids, sortedKeys } = this._resolveZoneIds(context.locale().localeString());
180
198
  for (const name of sortedKeys) {
181
199
  if (context.subSequenceEquals(text, position, name, 0, name.length)) {
182
200
  context.setParsedZone(ZoneId.of(ids[name]));
package/src/plug.js CHANGED
@@ -11,6 +11,8 @@ import LocaleDateTimeFormatter from './format/LocaleDateTimeFormatter';
11
11
  import './_init';
12
12
 
13
13
  /**
14
+ * @private
15
+ *
14
16
  * plugin Function, call using js-jodas use()
15
17
  *
16
18
  * @param jsJoda
@@ -28,4 +30,6 @@ export default function (jsJoda) {
28
30
  jsJoda.DateTimeFormatter.prototype[prop] = LocaleDateTimeFormatter.prototype[prop];
29
31
  }
30
32
  });
33
+ // copy statics manually
34
+ jsJoda.DateTimeFormatter.RFC_1123_DATE_TIME = LocaleDateTimeFormatter.RFC_1123_DATE_TIME;
31
35
  }
@@ -480,7 +480,7 @@ export class ComputedDayOfField {
480
480
 
481
481
  //-----------------------------------------------------------------------
482
482
  toString() {
483
- return this._name + '[' + this._weekDef.toString() + ']';
483
+ return `${this._name}[${this._weekDef.toString()}]`;
484
484
  }
485
485
  }
486
486
 
@@ -946,7 +946,7 @@ export class WeekFields {
946
946
  * @return the string representation, not null
947
947
  */
948
948
  toString() {
949
- return 'WeekFields[' + this._firstDayOfWeek + ',' + this._minimalDays + ']';
949
+ return `WeekFields[${this._firstDayOfWeek},${this._minimalDays}]`;
950
950
  }
951
951
 
952
952
  }
@@ -1,3 +1,6 @@
1
+ /* eslint-disable */
2
+ // we must use es5 compatible code in this post install file
3
+
1
4
  /*
2
5
  * @copyright (c) 2018, Philipp Thuerwaechter & Pattrick Hueper
3
6
  * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
@@ -11,5 +14,5 @@
11
14
  * that cldr-data is installed in parallel!
12
15
  */
13
16
  module.exports = function (cldrPath) {
14
- return require('../node_modules/cldr-data/' + cldrPath);
17
+ return require('../node_modules/cldr-data/'.concat(cldrPath));
15
18
  };
@@ -1,15 +0,0 @@
1
- /*
2
- * @copyright (c) 2017, Philipp Thuerwaechter & Pattrick Hueper
3
- * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
4
- */
5
-
6
- /* since the npm cldrData load is using `fs` and other modules not available in browser,
7
- * we define our own cldrData "load" function that just `requires` a cldr-data file
8
- */
9
-
10
- /* NOTE: the path is relative to the installed js-joda-locale package and assuming,
11
- * that cldr-data is installed in parallel!
12
- */
13
- module.exports = function (cldrPath) {
14
- return require('../../cldr-data/' + cldrPath);
15
- };