@brightspace-ui/intl 3.40.1 → 3.41.0

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 (35) hide show
  1. package/lib/common.js +8 -2
  2. package/lib/dateTime.js +202 -324
  3. package/lib/document-locale-settings.js +1 -1
  4. package/lib/locale-data/current.js +54 -0
  5. package/lib/locale-data/locales/ar.js +430 -0
  6. package/lib/locale-data/locales/ca.js +427 -0
  7. package/lib/locale-data/locales/cy.js +419 -0
  8. package/lib/locale-data/locales/da.js +414 -0
  9. package/lib/locale-data/locales/de.js +421 -0
  10. package/lib/locale-data/locales/en-CA.js +453 -0
  11. package/lib/locale-data/locales/en-GB.js +458 -0
  12. package/lib/locale-data/locales/en.js +452 -0
  13. package/lib/locale-data/locales/es-419.js +426 -0
  14. package/lib/locale-data/locales/es.js +425 -0
  15. package/lib/locale-data/locales/fr-CA-u-sd-caon.js +422 -0
  16. package/lib/locale-data/locales/fr-CA.js +422 -0
  17. package/lib/locale-data/locales/fr.js +419 -0
  18. package/lib/locale-data/locales/haw.js +371 -0
  19. package/lib/locale-data/locales/hi.js +424 -0
  20. package/lib/locale-data/locales/ja.js +431 -0
  21. package/lib/locale-data/locales/ko.js +435 -0
  22. package/lib/locale-data/locales/mi.js +384 -0
  23. package/lib/locale-data/locales/nl.js +417 -0
  24. package/lib/locale-data/locales/pl.js +421 -0
  25. package/lib/locale-data/locales/pt.js +423 -0
  26. package/lib/locale-data/locales/ru.js +421 -0
  27. package/lib/locale-data/locales/sv.js +426 -0
  28. package/lib/locale-data/locales/th.js +440 -0
  29. package/lib/locale-data/locales/tr.js +432 -0
  30. package/lib/locale-data/locales/ur.js +270 -0
  31. package/lib/locale-data/locales/vi.js +425 -0
  32. package/lib/locale-data/locales/zh-Hant.js +430 -0
  33. package/lib/locale-data/locales/zh.js +425 -0
  34. package/lib/locale-data/supported.js +14 -9
  35. package/package.json +1 -3
package/lib/common.js CHANGED
@@ -34,7 +34,7 @@ export function getLanguage() {
34
34
  return langTag;
35
35
  }
36
36
 
37
- export function merge(obj1, obj2) {
37
+ export function merge(obj1, obj2, keepOriginal = false) {
38
38
  if (obj2 === undefined || obj2 === null || typeof(obj2) !== 'object') {
39
39
  return;
40
40
  }
@@ -44,10 +44,12 @@ export function merge(obj1, obj2) {
44
44
  if (typeof(obj2[i]) === 'object' && typeof(obj1[i]) === 'object') {
45
45
  merge(obj1[i], obj2[i]);
46
46
  } else {
47
+ if (keepOriginal) obj1[`_original_${i}`] = obj1[i];
47
48
  obj1[i] = obj2[i];
48
49
  }
49
50
  }
50
51
  }
52
+ return obj1;
51
53
  }
52
54
 
53
55
  export function validateFormatValue(value) {
@@ -82,7 +84,11 @@ function updateLocalNames() {
82
84
  return;
83
85
  }
84
86
  supportedLocalesDetails.forEach(l => {
85
- l.localName = localName.of(l.overrideCode || l.code);
87
+ try {
88
+ l.localName = localName.of(l.overrideCode);
89
+ } catch {
90
+ l.localName = localName.of(l.code);
91
+ }
86
92
  });
87
93
  }
88
94
 
package/lib/dateTime.js CHANGED
@@ -1,8 +1,6 @@
1
- import { getDocumentLocaleSettings, getLanguage, merge } from './common.js';
2
-
3
- // to-do: These should be based on region, not language
4
- const hour24locales = ['ca', 'cy', 'da', 'de', 'es', 'fr', 'nl', 'pt', 'sv', 'tr', 'zh'];
5
- const mondayFirstDayLocales = ['ca', 'cy', 'da', 'de', 'fr', 'hi', 'mi', 'nl', 'sv', 'tr'];
1
+ import { getDocumentLocaleSettings, merge } from './common.js';
2
+ import { localeData } from './locale-data/current.js';
3
+ import { resolveSupportedLocale } from './locale-data/supported.js';
6
4
 
7
5
  // timezone abbreviations and offsets from https://www.timeanddate.com/time/zones/
8
6
  const timezoneOffsetMap = {
@@ -352,8 +350,7 @@ function getParts() {
352
350
  const descriptor = getDateTimeDescriptor();
353
351
 
354
352
  const result = [];
355
- const separator = getSeparator();
356
- const parts = descriptor.formats.dateFormats.short.split(separator);
353
+ const parts = descriptor.formats.dateFormats.short.split(/\W+/).filter(e => e);
357
354
 
358
355
  for (let i = 0; i < parts.length; i++) {
359
356
  const part = parts[i].trim();
@@ -381,45 +378,6 @@ function getParts() {
381
378
 
382
379
  }
383
380
 
384
- const reSeparator = new RegExp('\\W');
385
-
386
- function getSeparator() {
387
- const descriptor = getDateTimeDescriptor();
388
- const match = reSeparator.exec(descriptor.formats.dateFormats.short);
389
- if (match !== null) {
390
- return match[0];
391
- }
392
- return '/';
393
- }
394
-
395
- function getTimeFormat(hour24, language, baseLanguage) {
396
-
397
- if (hour24 && baseLanguage === 'fr') {
398
- return 'HH\' h \'mm';
399
- }
400
-
401
- let timeFormat = hour24 ? 'HH:mm' : 'h:mm';
402
-
403
- // non-zero padded 24-hour clocks and zero-padded 12-hour clocks
404
- if (hour24 && (baseLanguage === 'ca' || baseLanguage === 'ja' || language === 'pt-br' || (baseLanguage === 'zh' && language !== 'zh-tw'))) {
405
- timeFormat = 'H:mm';
406
- } else if (!hour24 && language === 'zh-tw') {
407
- timeFormat = 'hh:mm';
408
- }
409
-
410
- if (!hour24) {
411
- // AM/PM before vs. after
412
- if (baseLanguage === 'ko' || baseLanguage === 'zh') {
413
- timeFormat = `tt ${timeFormat}`;
414
- } else {
415
- timeFormat = `${timeFormat} tt`;
416
- }
417
- }
418
-
419
- return timeFormat;
420
-
421
- }
422
-
423
381
  function getTimezoneFromDuplicatedAbbreviation(abbrTimezone) {
424
382
  const longTimezone = getDocumentLocaleSettings().timezone.identifier;
425
383
  switch (abbrTimezone) {
@@ -692,300 +650,218 @@ export function convertUTCToLocalDateTime(date) {
692
650
  return convertJsDateToLocalDateTime(utcDate) || date;
693
651
  }
694
652
 
653
+ function convertCldrDatePattern(pattern) {
654
+ let result = '';
655
+ let i = 0;
656
+ while (i < pattern.length) {
657
+ const c = pattern.charAt(i);
658
+ if (c === "'") {
659
+ // Quoted literal — pass through including quotes
660
+ result += c;
661
+ i++;
662
+ while (i < pattern.length && pattern.charAt(i) !== "'") {
663
+ result += pattern.charAt(i);
664
+ i++;
665
+ }
666
+ if (i < pattern.length) {
667
+ result += pattern.charAt(i); // closing quote
668
+ i++;
669
+ }
670
+ } else if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
671
+ // Collect run of same letter
672
+ let token = c;
673
+ i++;
674
+ while (i < pattern.length && pattern.charAt(i) === c) {
675
+ token += pattern.charAt(i);
676
+ i++;
677
+ }
678
+ // Convert CLDR token to descriptor token
679
+ switch (token) {
680
+ case 'EEEE':
681
+ result += 'dddd';
682
+ break;
683
+ case 'E':
684
+ case 'EE':
685
+ case 'EEE':
686
+ result += 'ddd';
687
+ break;
688
+ case 'y':
689
+ result += 'yyyy';
690
+ break;
691
+ case 'yyyy':
692
+ result += 'yyyy';
693
+ break;
694
+ default:
695
+ // Unknown date token — pass through as-is
696
+ result += token;
697
+ break;
698
+ }
699
+ } else {
700
+ // Non-ASCII or punctuation — literal, pass through
701
+ result += c;
702
+ i++;
703
+ }
704
+ }
705
+ return result;
706
+ }
707
+
708
+ function convertCldrTimePattern(pattern) {
709
+ let result = '';
710
+ let i = 0;
711
+ while (i < pattern.length) {
712
+ const c = pattern.charAt(i);
713
+ if (c === "'") {
714
+ // Quoted literal — pass through including quotes
715
+ result += c;
716
+ i++;
717
+ while (i < pattern.length && pattern.charAt(i) !== "'") {
718
+ result += pattern.charAt(i);
719
+ i++;
720
+ }
721
+ if (i < pattern.length) {
722
+ result += pattern.charAt(i); // closing quote
723
+ i++;
724
+ }
725
+ } else if (c === '[' || c === ']') {
726
+ // Skip brackets (used around timezone in some CLDR patterns)
727
+ i++;
728
+ } else if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
729
+ // Collect run of same letter
730
+ let token = c;
731
+ i++;
732
+ while (i < pattern.length && pattern.charAt(i) === c) {
733
+ token += pattern.charAt(i);
734
+ i++;
735
+ }
736
+ // Convert CLDR time token to descriptor token
737
+ switch (token) {
738
+ case 'a':
739
+ case 'B':
740
+ result += 'tt';
741
+ break;
742
+ case 'h':
743
+ result += 'h';
744
+ break;
745
+ case 'hh':
746
+ result += 'hh';
747
+ break;
748
+ case 'H':
749
+ result += 'H';
750
+ break;
751
+ case 'HH':
752
+ result += 'HH';
753
+ break;
754
+ case 'm':
755
+ result += 'mm';
756
+ break;
757
+ case 'mm':
758
+ result += 'mm';
759
+ break;
760
+ default:
761
+ // Unknown time token — pass through as-is
762
+ result += token;
763
+ break;
764
+ }
765
+ } else {
766
+ // Non-ASCII or punctuation — literal, pass through
767
+ result += c;
768
+ i++;
769
+ }
770
+ }
771
+ // Trim leading/trailing whitespace and trailing separators
772
+ result = result.replace(/^[\s:.\u002D]+/, '').replace(/[\s:.\u002D]+$/, '');
773
+ return result;
774
+ }
775
+
776
+ function isTimezoneFirst(longFormat) {
777
+ return ['z', 'v'].includes(longFormat.replace(/'.+'/, '').match(/([zv])|([HhaBm])/)[0]);
778
+ }
779
+
695
780
  export function getDateTimeDescriptor() {
696
781
  const settings = getDocumentLocaleSettings();
697
782
  return settings.getCacheItem('dateTimeDescriptor', () => {
698
783
 
699
- const language = getLanguage();
700
- const subtags = language.split('-');
701
- const baseLanguage = subtags[0];
702
-
703
- let hour24 = (hour24locales.indexOf(baseLanguage) > -1);
704
- if (language === 'zh-tw') {
705
- hour24 = false;
706
- }
784
+ // Determine hour24 from locale data
785
+ const nativeHour24 = /H/.test(localeData.timeFormats.short);
786
+ let hour24 = nativeHour24;
707
787
  if (settings.overrides.date && settings.overrides.date.hour24 !== undefined) {
708
788
  hour24 = settings.overrides.date.hour24;
709
789
  }
710
790
 
711
- const timeFormat = getTimeFormat(hour24, language, baseLanguage);
712
-
713
- let dateFormats = ['dddd, MMMM d, yyyy', 'MMM d, yyyy', 'M/d/yyyy', 'MMMM yyyy', 'MMMM d', 'MMM d'];
714
- const fullTimeFormat = (baseLanguage === 'zh' && language !== 'zh-tw') ? `ZZZ ${timeFormat}` : `${timeFormat} ZZZ`;
715
- let dayPeriods = ['AM', 'PM'];
716
- let months = [
717
- ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
718
- ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
719
- ];
720
- let days = [
721
- ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
722
- ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
723
- ['S', 'M', 'T', 'W', 'T', 'F', 'S']
724
- ];
725
- let firstDayOfWeek = (mondayFirstDayLocales.indexOf(baseLanguage) > -1) ? 1 : 0;
726
- let weekendStartDay = 6;
727
- let weekendEndDay = 0;
728
-
729
- switch (baseLanguage) {
730
- case 'ar':
731
- dateFormats = ['dddd, d MMMM, yyyy', 'dd MMMM, yyyy', 'dd/MM/yyyy', 'MMMM, yyyy', 'd MMMM', 'd MMM'];
732
- dayPeriods = ['ص', 'م'];
733
- months[0] = months[1] = ['يناير', 'فبراير', 'مارس', 'أبريل', 'مايو', 'يونيو', 'يوليو', 'أغسطس', 'سبتمبر', 'أكتوبر', 'نوفمبر', 'ديسمبر'];
734
- days = [
735
- ['الأحد', 'الإثنين', 'الثلاثاء', 'الأربعاء', 'الخميس', 'الجمعة', 'السبت'],
736
- ['أحد', 'إثنين', 'ثلاثاء', 'أربعاء', 'خميس', 'جمعة', 'سبت'],
737
- ['أ', 'إ', 'ث', 'أر', 'خ', 'ج', 'س']
738
- ];
739
- firstDayOfWeek = 6;
740
- weekendStartDay = 4;
741
- weekendEndDay = 5;
742
- break;
743
- case 'ca':
744
- dateFormats = ['dddd, d\' de \'MMMM\' del \'yyyy', 'd\' de \'MMMM\' del \'yyyy', 'd/M/yy', 'MMMM\' del \'yyyy', 'd\' de \'MMMM', 'd\' de \'MMM'];
745
- dayPeriods = ['a. m.', 'p. m.'];
746
- months = [
747
- ['gener', 'febrer', 'març', 'abril', 'maig', 'juny', 'juliol', 'agost', 'setembre', 'octubre', 'novembre', 'desembre'],
748
- ['gen.', 'febr.', 'març', 'abr.', 'maig', 'juny', 'jul.', 'ag.', 'set.', 'oct.', 'nov.', 'des.']
749
- ];
750
- days = [
751
- ['diumenge', 'dilluns', 'dimarts', 'dimecres', 'dijous', 'divendres', 'dissabte'],
752
- ['dg.', 'dl.', 'dt.', 'dc.', 'dj.', 'dv.', 'ds.'],
753
- ['dg.', 'dl.', 'dt.', 'dc.', 'dj.', 'dv.', 'ds.'],
754
- ];
755
- break;
756
- case 'cy':
757
- dateFormats = ['dddd, d MMMM yyyy', 'dd MMMM yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
758
- months = [
759
- ['Ionawr', 'Chwefror', 'Mawrth', 'Ebrill', 'Mai', 'Mehefin', 'Gorffennaf', 'Awst', 'Medi', 'Hydref', 'Tachwedd', 'Rhagfyr'],
760
- ['Ion', 'Chwe', 'Maw', 'Ebr', 'Mai', 'Meh', 'Gor', 'Awst', 'Medi', 'Hyd', 'Tach', 'Rhag']
761
- ];
762
- days = [
763
- ['Dydd Sul', 'Dydd Llun', 'Dydd Mawrth', 'Dydd Mercher', 'Dydd Iau', 'Dydd Gwener', 'Dydd Sadwrn'],
764
- ['Sul', 'Llun', 'Maw', 'Mer', 'Iau', 'Gwe', 'Sad'],
765
- ['Su', 'Ll', 'Ma', 'Me', 'Ia', 'Gw', 'Sa']
766
- ];
767
- break;
768
- case 'da':
769
- dateFormats = ['dddd \'den\' d. MMMM yyyy', 'd. MMM. yyyy', 'dd.MM.yyyy', 'MMMM yyyy', 'd. MMMM', 'd. MMM'];
770
- months = [
771
- ['januar', 'februar', 'marts', 'april', 'maj', 'juni', 'juli', 'august', 'september', 'oktober', 'november', 'december'],
772
- ['jan.', 'feb.', 'mar.', 'apr.', 'maj', 'jun.', 'jul.', 'aug.', 'sep.', 'okt.', 'nov.', 'dec.']
773
- ];
774
- days = [
775
- ['søndag', 'mandag', 'tirsdag', 'onsdag', 'torsdag', 'fredag', 'lørdag'],
776
- ['søn.', 'man.', 'tir.', 'ons.', 'tor.', 'fre.', 'lør.'],
777
- ['S', 'M', 'T', 'O', 'T', 'F', 'L']
778
- ];
779
- break;
780
- case 'de':
781
- dateFormats = ['dddd d. MMMM yyyy', 'd. MMMM yyyy', 'dd.MM.yyyy', 'MMMM yyyy', 'd. MMMM', 'd. MMM'];
782
- months = [
783
- ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
784
- ['Jan.', 'Feb.', 'März', 'Apr.', 'Mai', 'Juni', 'Juli', 'Aug.', 'Sept.', 'Okt.', 'Nov.', 'Dez.']
785
- ];
786
- days = [
787
- ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
788
- ['So.', 'Mo.', 'Di.', 'Mi.', 'Do.', 'Fr.', 'Sa.'],
789
- ['S', 'M', 'D', 'M', 'D', 'F', 'S']
790
- ];
791
- break;
792
- case 'es':
793
- dateFormats = ['dddd d\' de \'MMMM\' de \'yyyy', 'd\' de \'MMMM\' de \'yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd\' de \'MMMM', 'd\' de \'MMM'];
794
- dayPeriods = ['a. m.', 'p. m.'];
795
- months = [
796
- ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre', 'octubre', 'noviembre', 'diciembre'],
797
- ['ene.', 'feb.', 'mar.', 'abr.', 'may.', 'jun.', 'jul.', 'ago.', 'sep.', 'oct.', 'nov.', 'dic.']
798
- ];
799
- days = [
800
- ['domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado'],
801
- ['dom.', 'lun.', 'mar.', 'mié.', 'jue.', 'vie.', 'sáb.'],
802
- ['D', 'L', 'M', 'M', 'J', 'V', 'S']
803
- ];
804
- break;
805
- case 'fr':
806
- dateFormats = ['dddd d MMMM yyyy', 'd MMM yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
807
- months = [
808
- ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'],
809
- ['janv.', 'févr.', 'mars', 'avr.', 'mai', 'juin', 'juil.', 'août', 'sept.', 'oct.', 'nov.', 'déc.']
810
- ];
811
- days = [
812
- ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'],
813
- ['dim.', 'lun.', 'mar.', 'mer.', 'jeu.', 'ven.', 'sam.'],
814
- ['D', 'L', 'M', 'M', 'J', 'V', 'S']
815
- ];
816
- break;
817
- case 'haw':
818
- dateFormats = ['dddd, d MMMM yyyy', 'd MMM yyyy', 'd/M/yyyy', 'yyyy MMMM', 'd MMMM', 'd MMM'];
819
- months = [
820
- ['Ianuali', 'Pepeluali', 'Malaki', 'ʻApelila', 'Mei', 'Iune', 'Iulai', 'ʻAukake', 'Kepakemapa', 'ʻOkakopa', 'Nowemapa', 'Kekemapa'],
821
- ['Ian.', 'Pep.', 'Mal.', 'ʻAp.', 'Mei', 'Iun.', 'Iul.', 'ʻAu.', 'Kep.', 'ʻOk.', 'Now.', 'Kek.']
822
- ];
823
- days = [
824
- ['Lāpule', 'Poʻakahi', 'Poʻalua', 'Poʻakolu', 'Poʻahā', 'Poʻalima', 'Poʻaono'],
825
- ['LP', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6'],
826
- ['S', 'M', 'T', 'W', 'T', 'F', 'S']
827
- ];
828
- break;
829
- case 'hi':
830
- dateFormats = ['dddd, d MMMM yyyy', 'd MMMM yyyy', 'dd-MM-yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
831
- dayPeriods = ['पूर्वाह्न', 'अपराह्न'];
832
- months = [
833
- ['जनवरी', 'फरवरी', 'मार्च', 'अप्रैल', 'मई', 'जून', 'जुलाई', 'अगस्त', 'सितंबर', 'अक्टूबर', 'नवंबर', 'दिसंबर'],
834
- ['जन', 'फर', 'मार्च', 'अप्रैल', 'मई', 'जून', 'जुलाई', 'अग', 'सितं', 'अक्टू', 'नवं', 'दिसं']
835
- ];
836
- days = [
837
- ['रविवार', 'सोमवार', 'मंगलवार', 'बुधवार', 'गुरूवार', 'शुक्रवार', 'शनिवार'],
838
- ['रवि', 'सोम', 'मंगल', 'बुध', 'गुरु', 'शुक्र', 'शनि'],
839
- ['र', 'सो', 'मं', 'बु', 'गु', 'शु', 'श']
840
- ];
841
- break;
842
- case 'ja':
843
- dateFormats = ['yyyy年M月d日', 'yyyy年M月d日', 'yyyy/MM/dd', 'yyyy年M月', 'M月d日', 'M月d日'];
844
- dayPeriods = ['午前', '午後'];
845
- months[0] = months[1] = ['1 月', '2 月', '3 月', '4 月', '5 月', '6 月', '7 月', '8 月', '9 月', '10 月', '11 月', '12 月'];
846
- days[0] = days[1] = days[2] = ['日', '月', '火', '水', '木', '金', '土'];
847
- break;
848
- case 'ko':
849
- dateFormats = ['yyyy년 M월 d일 dddd', 'yyyy년 M월 d일', 'yyyy-MM-dd', 'yyyy년 M월', 'M월 d일', 'MMM d일'];
850
- dayPeriods = ['오전', '오후'];
851
- months[0] = months[1] = ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월'];
852
- days[0] = ['일요일', '월요일', '화요일', '수요일', '목요일', '금요일', '토요일'];
853
- days[1] = days[2] = ['일', '월', '화', '수', '목', '금', '토'];
854
- break;
855
- case 'mi':
856
- dateFormats = ['dddd, d MMMM y', 'd MMMM y', 'dd-MM-y', 'MMMM yyyy', 'd MMMM', 'd MMM'];
857
- months = [
858
- ['Kohitātea', 'Huitanguru', 'Poutūterangi', 'Paengawhāwhā', 'Haratua', 'Pipiri', 'Hōngongoi', 'Hereturikōkā', 'Mahuru', 'Whiringa-ā-nuku', 'Whiringa-ā-rangi', 'Hakihea'],
859
- ['Kohi', 'Hui', 'Pou', 'Pae', 'Hara', 'Pipi', 'Hōngo', 'Here', 'Mahu', 'Nuku', 'Rangi', 'Haki']
860
- ];
861
- days = [
862
- ['Rātapu', 'Rāhina', 'Rātū', 'Rāapa', 'Rāpare', 'Rāmere', 'Rāhoroi'],
863
- ['Tap', 'Hin', 'Tū', 'Apa', 'Par', 'Mer', 'Hor'],
864
- ['T', 'H', 'T', 'A', 'P', 'M', 'H']
865
- ];
866
- break;
867
- case 'nl':
868
- dateFormats = ['dddd d MMMM yyyy', 'd MMMM yyyy', 'dd-MM-yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
869
- dayPeriods = ['a.m.', 'p.m.'];
870
- months = [
871
- ['januari', 'februari', 'maart', 'april', 'mei', 'juni', 'juli', 'augustus', 'september', 'oktober', 'november', 'december'],
872
- ['jan.', 'feb.', 'mrt.', 'apr.', 'mei', 'jun.', 'jul.', 'aug.', 'sep.', 'okt.', 'nov.', 'dec.']
873
- ];
874
- days = [
875
- ['zondag', 'maandag', 'dinsdag', 'woensdag', 'donderdag', 'vrijdag', 'zaterdag'],
876
- ['zo', 'ma', 'di', 'wo', 'do', 'vr', 'za'],
877
- ['Z', 'M', 'D', 'W', 'D', 'V', 'Z']
878
- ];
879
- break;
880
- case 'pt':
881
- dateFormats = ['dddd, d\' de \'MMMM\' de \'yyyy', 'd\' de \'MMMM\' de \'yyyy', 'dd/MM/yyyy', 'MMMM\' de \'yyyy', 'dd\' de \'MMMM', 'dd\' de \'MMM'];
882
- months = [
883
- ['janeiro', 'fevereiro', 'março', 'abril', 'maio', 'junho', 'julho', 'agosto', 'setembro', 'outubro', 'novembro', 'dezembro'],
884
- ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez']
885
- ];
886
- days = [
887
- ['domingo', 'segunda-feira', 'terça-feira', 'quarta-feira', 'quinta-feira', 'sexta-feira', 'sábado'],
888
- ['dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb'],
889
- ['D', 'S', 'T', 'Q', 'Q', 'S', 'S']
890
- ];
891
- break;
892
- case 'sv':
893
- dateFormats = ['dddd \'den\' d MMMM yyyy', 'd MMMM yyyy', 'yyyy-MM-dd', 'MMMM yyyy', 'dd MMMM', 'dd MMM'];
894
- dayPeriods = ['fm', 'em'];
895
- months = [
896
- ['januari', 'februari', 'mars', 'april', 'maj', 'juni', 'juli', 'augusti', 'september', 'oktober', 'november', 'december'],
897
- ['jan.', 'feb.', 'mars', 'apr.', 'maj', 'juni', 'juli', 'aug.', 'sep.', 'okt.', 'nov.', 'dec.']
898
- ];
899
- days = [
900
- ['Söndag', 'Måndag', 'Tisdag', 'Onsdag', 'Torsdag', 'Fredag', 'Lördag'],
901
- ['Sön', 'Mån', 'Tis', 'Ons', 'Tor', 'Fre', 'Lör'],
902
- ['S', 'M', 'T', 'O', 'T', 'F', 'L']
903
- ];
904
- break;
905
- case 'tr':
906
- dateFormats = ['dd MMMM yyyy dddd', 'dd MMMM yyyy', 'dd.MM.yyyy', 'MMMM yyyy', 'dd MMMM', 'dd MMM'];
907
- dayPeriods = ['ÖÖ', 'ÖS'];
908
- months = [
909
- ['Ocak', 'Şubat', 'Mart', 'Nisan', 'Mayıs', 'Haziran', 'Temmuz', 'Ağustos', 'Eylül', 'Ekim', 'Kasım', 'Aralık'],
910
- ['Oca', 'Şub', 'Mar', 'Nis', 'May', 'Haz', 'Tem', 'Ağu', 'Eyl', 'Ek', 'Kas', 'Ara']
911
- ];
912
- days = [
913
- ['Pazar', 'Pazartesi', 'Salı', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi'],
914
- ['Paz', 'Pzt', 'Sal', 'Çar', 'Per', 'Cum', 'Cmt'],
915
- ['P', 'P', 'S', 'Ç', 'P', 'C', 'C']
916
- ];
917
- break;
918
- case 'zh':
919
- dateFormats = ['yyyy年M月d日', 'yyyy年M月d日', 'yyyy/M/d', 'yyyy年M月', 'M月d日', 'M月d日'];
920
- dayPeriods = ['上午', '下午'];
921
- months[0] = months[1] = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
922
- days[0] = days[1] = ['週日', '週一', '週二', '週三', '週四', '週五', '週六'];
923
- days[2] = ['日', '一', '二', '三', '四', '五', '六'];
924
- break;
925
- }
926
-
927
- switch (language) {
928
- case 'en-gb':
929
- dateFormats = ['dddd, d MMMM yyyy', 'dd MMMM yyyy', 'dd/MM/yyyy', 'MMMM yyyy', 'd MMMM', 'd MMM'];
930
- break;
931
- case 'fr-ca':
932
- dateFormats[1] = 'MMM d yyyy';
933
- dateFormats[2] = 'yyyy-MM-dd';
934
- dateFormats[4] = 'MMMM d';
935
- dateFormats[5] = 'MMM d';
936
- firstDayOfWeek = 0;
937
- break;
938
- case 'fr-on':
939
- dateFormats[0] = 'dddd\' le \'d MMMM yyyy';
940
- dateFormats[1] = 'MMM d yyyy';
941
- dateFormats[2] = 'yyyy-MM-dd';
942
- firstDayOfWeek = 0;
943
- break;
944
- case 'zh-tw':
945
- days[0] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
946
- break;
791
+ // Pick time pattern based on effective hour24
792
+ let timeSourcePattern;
793
+ if (hour24) {
794
+ timeSourcePattern = nativeHour24 ? localeData.timeFormats.short : localeData.dateFormatItems.Hm;
795
+ } else {
796
+ timeSourcePattern = !nativeHour24 ? localeData.timeFormats.short : localeData.dateFormatItems.hm;
947
797
  }
798
+ const timeFormatShort = convertCldrTimePattern(timeSourcePattern);
799
+
800
+ // Determine timezone placement from long time format
801
+ const tzFirst = isTimezoneFirst(localeData.timeFormats.long);
802
+ const fullTimeFormat = tzFirst ? `ZZZ ${timeFormatShort}` : `${timeFormatShort} ZZZ`;
803
+
804
+ // Convert date formats from CLDR
805
+ const dateFormats = {
806
+ 'full': convertCldrDatePattern(localeData.dateFormats.full),
807
+ //'long': convertCldrDatePattern(localeData.dateFormats.long, false),
808
+ 'medium': convertCldrDatePattern(localeData.dateFormats.medium),
809
+ 'short': convertCldrDatePattern(localeData.dateFormats.short),
810
+ 'monthYear': convertCldrDatePattern(localeData.dateFormatItems.yMMMM),
811
+ 'monthDay': convertCldrDatePattern(localeData.dateFormatItems.MMMMd),
812
+ 'shortMonthDay': convertCldrDatePattern(localeData.dateFormatItems.MMMd),
813
+ 'longDayOfWeek': 'cccc',
814
+ 'shortDayOfWeek': convertCldrDatePattern(localeData.dateFormatItems.E),
815
+ 'longMonth': 'LLLL',
816
+ 'shortMonth': convertCldrDatePattern(localeData.dateFormatItems.MMM)
817
+ };
948
818
 
949
819
  const descriptor = {
950
820
  hour24: hour24,
951
821
  formats: {
952
- dateFormats: {
953
- 'full': dateFormats[0],
954
- 'medium': dateFormats[1],
955
- 'short': dateFormats[2],
956
- 'monthYear': dateFormats[3],
957
- 'monthDay': dateFormats[4],
958
- 'shortMonthDay': dateFormats[5],
959
- 'longDayOfWeek': 'dddd',
960
- 'shortDayOfWeek': 'ddd',
961
- 'longMonth': 'MMMM',
962
- 'shortMonth': 'MMM'
963
- },
822
+ dateFormats: dateFormats,
964
823
  timeFormats: {
965
824
  'full': fullTimeFormat,
966
- 'medium': timeFormat,
967
- 'short': timeFormat
825
+ 'medium': timeFormatShort, // forced to short to maintain current behavior
826
+ 'short': timeFormatShort,
968
827
  }
969
828
  },
970
829
  calendar: {
971
- firstDayOfWeek: firstDayOfWeek,
972
- weekendStartDay: weekendStartDay,
973
- weekendEndDay: weekendEndDay,
830
+ firstDayOfWeek: localeData.weekData.firstDay,
831
+ weekendStartDay: localeData.weekData.weekendStart,
832
+ weekendEndDay: localeData.weekData.weekendEnd,
974
833
  months: {
975
- short: months[1],
976
- long: months[0]
834
+ short: localeData.months.format.abbreviated,
835
+ long: localeData.months.format.wide
836
+ },
837
+ monthsStandAlone: {
838
+ abbreviated: localeData.months.standAlone.abbreviated,
839
+ wide: localeData.months.standAlone.wide
977
840
  },
978
841
  days: {
979
- narrow: days[2],
980
- short: days[1],
981
- long: days[0]
842
+ narrow: localeData.dayNames.format.narrow,
843
+ short: localeData.dayNames.format.abbreviated,
844
+ long: localeData.dayNames.format.wide
845
+ },
846
+ daysStandAlone: {
847
+ narrow: localeData.dayNames.standAlone.narrow,
848
+ abbreviated: localeData.dayNames.standAlone.abbreviated,
849
+ wide: localeData.dayNames.standAlone.wide
982
850
  },
983
- dayPeriods: { am: dayPeriods[0], pm: dayPeriods[1] }
851
+ dayPeriods: {
852
+ am: localeData.dayPeriods.format.abbreviated.am,
853
+ pm: localeData.dayPeriods.format.abbreviated.pm
854
+ }
984
855
  }
985
856
  };
986
857
 
987
858
  if (settings.overrides.date) {
988
- merge(descriptor, settings.overrides.date);
859
+ if (settings.overrides.date.calendar && settings.language.startsWith(resolveSupportedLocale(settings.language).toLowerCase())) {
860
+ // prefer more nuanced front-end data
861
+ delete settings.overrides.date.calendar.months;
862
+ delete settings.overrides.date.calendar.days;
863
+ }
864
+ return merge(JSON.parse(JSON.stringify(descriptor)), settings.overrides.date);
989
865
  }
990
866
 
991
867
  return descriptor;
@@ -999,22 +875,20 @@ export function formatTime(date, options) {
999
875
  const settings = getDocumentLocaleSettings();
1000
876
 
1001
877
  options = options || {};
1002
-
1003
878
  const timezone = options.timezone || settings.timezone.name;
1004
879
  const format = descriptor.formats.timeFormats[options.format]
1005
880
  || options.format || descriptor.formats.timeFormats['short'];
1006
881
 
1007
882
  const hour = date.getHours();
1008
- let hour12 = hour % 12;
1009
- if (hour12 === 0) {
1010
- hour12 = 12;
1011
- }
883
+ const hour12 = hour % 12;
1012
884
 
1013
885
  const replacements = {
1014
886
  'HH': prePadByZero(date.getHours(), 2),
1015
887
  'H': date.getHours().toString(),
1016
888
  'hh': prePadByZero(hour12, 2),
1017
- 'h': hour12,
889
+ 'h': hour12 || 12,
890
+ // K is unicode
891
+ 'K': hour12,
1018
892
  'mm': prePadByZero(date.getMinutes(), 2),
1019
893
  'tt': (hour > 11) ? descriptor.calendar.dayPeriods.pm : descriptor.calendar.dayPeriods.am,
1020
894
  'ZZZ': timezone
@@ -1109,10 +983,16 @@ export function formatDate(date, options) {
1109
983
  'ddd': descriptor.calendar.days.short[date.getDay()],
1110
984
  'dd': prePadByZero(date.getDate(), 2),
1111
985
  'd': date.getDate().toString(),
986
+ // c is unicode
987
+ 'cccc': descriptor.calendar.daysStandAlone.wide[date.getDay()],
988
+ 'ccc': descriptor.calendar.daysStandAlone.abbreviated[date.getDay()],
1112
989
  'MMMM': descriptor.calendar.months.long[date.getMonth()],
1113
990
  'MMM': descriptor.calendar.months.short[date.getMonth()],
1114
991
  'MM': prePadByZero((date.getMonth() + 1), 2),
1115
992
  'M': (date.getMonth() + 1).toString(),
993
+ // L is unicode
994
+ 'LLLL': descriptor.calendar.monthsStandAlone.wide[date.getMonth()],
995
+ 'LLL': descriptor.calendar.monthsStandAlone.abbreviated[date.getMonth()],
1116
996
  'yyyy': date.getFullYear().toString(),
1117
997
  'yy': date.getFullYear().toString().substr(2, 2)
1118
998
  };
@@ -1123,7 +1003,6 @@ export function formatDate(date, options) {
1123
1003
  }
1124
1004
 
1125
1005
  export function parseDate(input) {
1126
-
1127
1006
  if (input === undefined || input === null) {
1128
1007
  input = '';
1129
1008
  }
@@ -1132,10 +1011,9 @@ export function parseDate(input) {
1132
1011
  let year = null;
1133
1012
  let month = null;
1134
1013
  let day = null;
1135
- const separator = getSeparator();
1136
1014
  const dateFormatParts = getParts();
1137
1015
 
1138
- const dateParts = input.split(separator);
1016
+ const dateParts = input.split(/\W+/).filter(e => e);
1139
1017
  if (dateParts.length !== dateFormatParts.length) {
1140
1018
  throw new Error('Invalid input date: not enough parts');
1141
1019
  }
@@ -1272,7 +1150,7 @@ export function formatRelativeDateTime(then) {
1272
1150
  }
1273
1151
  }
1274
1152
 
1275
- const rtf = new Intl.RelativeTimeFormat(getLanguage(), {
1153
+ const rtf = new Intl.RelativeTimeFormat(localeData.sourceLocale, {
1276
1154
  localeMatcher: 'best fit',
1277
1155
  style: 'long',
1278
1156
  numeric
@@ -78,7 +78,7 @@ export class DocumentLocaleSettings {
78
78
 
79
79
  reset() {
80
80
  this._cache.clear();
81
- this._language = this._languageInitial;
81
+ this.language = this._languageInitial;
82
82
  this._listeners = [];
83
83
  Object.assign(this, JSON.parse(JSON.stringify(DEFAULTS)));
84
84
  }