@internationalized/date 3.5.6 → 3.6.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 (49) hide show
  1. package/LICENSE +201 -0
  2. package/dist/BuddhistCalendar.main.js +1 -2
  3. package/dist/BuddhistCalendar.main.js.map +1 -1
  4. package/dist/BuddhistCalendar.mjs +1 -2
  5. package/dist/BuddhistCalendar.module.js +1 -2
  6. package/dist/BuddhistCalendar.module.js.map +1 -1
  7. package/dist/DateFormatter.main.js.map +1 -1
  8. package/dist/DateFormatter.module.js.map +1 -1
  9. package/dist/EthiopicCalendar.main.js +2 -4
  10. package/dist/EthiopicCalendar.main.js.map +1 -1
  11. package/dist/EthiopicCalendar.mjs +2 -4
  12. package/dist/EthiopicCalendar.module.js +2 -4
  13. package/dist/EthiopicCalendar.module.js.map +1 -1
  14. package/dist/IndianCalendar.main.js +1 -2
  15. package/dist/IndianCalendar.main.js.map +1 -1
  16. package/dist/IndianCalendar.mjs +1 -2
  17. package/dist/IndianCalendar.module.js +1 -2
  18. package/dist/IndianCalendar.module.js.map +1 -1
  19. package/dist/IslamicCalendar.main.js +2 -4
  20. package/dist/IslamicCalendar.main.js.map +1 -1
  21. package/dist/IslamicCalendar.mjs +2 -4
  22. package/dist/IslamicCalendar.module.js +2 -4
  23. package/dist/IslamicCalendar.module.js.map +1 -1
  24. package/dist/JapaneseCalendar.main.js +1 -2
  25. package/dist/JapaneseCalendar.main.js.map +1 -1
  26. package/dist/JapaneseCalendar.mjs +1 -2
  27. package/dist/JapaneseCalendar.module.js +1 -2
  28. package/dist/JapaneseCalendar.module.js.map +1 -1
  29. package/dist/TaiwanCalendar.main.js +1 -2
  30. package/dist/TaiwanCalendar.main.js.map +1 -1
  31. package/dist/TaiwanCalendar.mjs +1 -2
  32. package/dist/TaiwanCalendar.module.js +1 -2
  33. package/dist/TaiwanCalendar.module.js.map +1 -1
  34. package/dist/conversion.main.js +1 -1
  35. package/dist/conversion.main.js.map +1 -1
  36. package/dist/conversion.mjs +1 -1
  37. package/dist/conversion.module.js +1 -1
  38. package/dist/conversion.module.js.map +1 -1
  39. package/dist/string.main.js +17 -8
  40. package/dist/string.main.js.map +1 -1
  41. package/dist/string.mjs +17 -8
  42. package/dist/string.module.js +17 -8
  43. package/dist/string.module.js.map +1 -1
  44. package/dist/types.d.ts +1 -4
  45. package/dist/types.d.ts.map +1 -1
  46. package/package.json +4 -3
  47. package/src/DateFormatter.ts +4 -8
  48. package/src/conversion.ts +1 -1
  49. package/src/string.ts +28 -8
@@ -12,10 +12,6 @@
12
12
 
13
13
  let formatterCache = new Map<string, Intl.DateTimeFormat>();
14
14
 
15
- interface ResolvedDateTimeFormatOptions extends Intl.ResolvedDateTimeFormatOptions {
16
- hourCycle?: Intl.DateTimeFormatOptions['hourCycle']
17
- }
18
-
19
15
  interface DateRangeFormatPart extends Intl.DateTimeFormatPart {
20
16
  source: 'startRange' | 'endRange' | 'shared'
21
17
  }
@@ -79,8 +75,8 @@ export class DateFormatter implements Intl.DateTimeFormat {
79
75
  }
80
76
 
81
77
  /** Returns the resolved formatting options based on the values passed to the constructor. */
82
- resolvedOptions(): ResolvedDateTimeFormatOptions {
83
- let resolvedOptions = this.formatter.resolvedOptions() as ResolvedDateTimeFormatOptions;
78
+ resolvedOptions(): Intl.ResolvedDateTimeFormatOptions {
79
+ let resolvedOptions = this.formatter.resolvedOptions();
84
80
  if (hasBuggyResolvedHourCycle()) {
85
81
  if (!this.resolvedHourCycle) {
86
82
  this.resolvedHourCycle = getResolvedHourCycle(resolvedOptions.locale, this.options);
@@ -156,10 +152,10 @@ function hasBuggyHour12Behavior() {
156
152
  let _hasBuggyResolvedHourCycle: boolean | null = null;
157
153
  function hasBuggyResolvedHourCycle() {
158
154
  if (_hasBuggyResolvedHourCycle == null) {
159
- _hasBuggyResolvedHourCycle = (new Intl.DateTimeFormat('fr', {
155
+ _hasBuggyResolvedHourCycle = new Intl.DateTimeFormat('fr', {
160
156
  hour: 'numeric',
161
157
  hour12: false
162
- }).resolvedOptions() as ResolvedDateTimeFormatOptions).hourCycle === 'h12';
158
+ }).resolvedOptions().hourCycle === 'h12';
163
159
  }
164
160
 
165
161
  return _hasBuggyResolvedHourCycle;
package/src/conversion.ts CHANGED
@@ -187,7 +187,7 @@ export function fromAbsolute(ms: number, timeZone: string): ZonedDateTime {
187
187
  let second = date.getUTCSeconds();
188
188
  let millisecond = date.getUTCMilliseconds();
189
189
 
190
- return new ZonedDateTime(year, month, day, timeZone, offset, hour, minute, second, millisecond);
190
+ return new ZonedDateTime(year < 1 ? 'BC' : 'AD', year < 1 ? -year + 1 : year, month, day, timeZone, offset, hour, minute, second, millisecond);
191
191
  }
192
192
 
193
193
  /**
package/src/string.ts CHANGED
@@ -18,10 +18,10 @@ import {GregorianCalendar} from './calendars/GregorianCalendar';
18
18
  import {Mutable} from './utils';
19
19
 
20
20
  const TIME_RE = /^(\d{2})(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
21
- const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
22
- const DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
23
- const ZONED_DATE_TIME_RE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:([+-]\d{2})(?::?(\d{2}))?)?\[(.*?)\]$/;
24
- const ABSOLUTE_RE = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:(?:([+-]\d{2})(?::?(\d{2}))?)|Z)$/;
21
+ const DATE_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})$/;
22
+ const DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
23
+ const ZONED_DATE_TIME_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:([+-]\d{2})(?::?(\d{2}))?)?\[(.*?)\]$/;
24
+ const ABSOLUTE_RE = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?(?:(?:([+-]\d{2})(?::?(\d{2}))?)|Z)$/;
25
25
  const DATE_TIME_DURATION_RE =
26
26
  /^((?<negative>-)|\+)?P((?<years>\d*)Y)?((?<months>\d*)M)?((?<weeks>\d*)W)?((?<days>\d*)D)?((?<time>T)((?<hours>\d*[.,]?\d{1,9})H)?((?<minutes>\d*[.,]?\d{1,9})M)?((?<seconds>\d*[.,]?\d{1,9})S)?)?$/;
27
27
  const requiredDurationTimeGroups = ['hours', 'minutes', 'seconds'];
@@ -66,8 +66,12 @@ export function parseDateTime(value: string): CalendarDateTime {
66
66
  throw new Error('Invalid ISO 8601 date time string: ' + value);
67
67
  }
68
68
 
69
+ let year = parseNumber(m[1], -9999, 9999);
70
+ let era = year < 1 ? 'BC' : 'AD';
71
+
69
72
  let date: Mutable<CalendarDateTime> = new CalendarDateTime(
70
- parseNumber(m[1], 1, 9999),
73
+ era,
74
+ year < 1 ? -year + 1 : year,
71
75
  parseNumber(m[2], 1, 12),
72
76
  1,
73
77
  m[4] ? parseNumber(m[4], 0, 23) : 0,
@@ -92,8 +96,12 @@ export function parseZonedDateTime(value: string, disambiguation?: Disambiguatio
92
96
  throw new Error('Invalid ISO 8601 date time string: ' + value);
93
97
  }
94
98
 
99
+ let year = parseNumber(m[1], -9999, 9999);
100
+ let era = year < 1 ? 'BC' : 'AD';
101
+
95
102
  let date: Mutable<ZonedDateTime> = new ZonedDateTime(
96
- parseNumber(m[1], 1, 9999),
103
+ era,
104
+ year < 1 ? -year + 1 : year,
97
105
  parseNumber(m[2], 1, 12),
98
106
  1,
99
107
  m[10],
@@ -136,8 +144,12 @@ export function parseAbsolute(value: string, timeZone: string): ZonedDateTime {
136
144
  throw new Error('Invalid ISO 8601 date time string: ' + value);
137
145
  }
138
146
 
147
+ let year = parseNumber(m[1], -9999, 9999);
148
+ let era = year < 1 ? 'BC' : 'AD';
149
+
139
150
  let date: Mutable<ZonedDateTime> = new ZonedDateTime(
140
- parseNumber(m[1], 1, 9999),
151
+ era,
152
+ year < 1 ? -year + 1 : year,
141
153
  parseNumber(m[2], 1, 12),
142
154
  1,
143
155
  timeZone,
@@ -180,7 +192,15 @@ export function timeToString(time: Time): string {
180
192
 
181
193
  export function dateToString(date: CalendarDate): string {
182
194
  let gregorianDate = toCalendar(date, new GregorianCalendar());
183
- return `${String(gregorianDate.year).padStart(4, '0')}-${String(gregorianDate.month).padStart(2, '0')}-${String(gregorianDate.day).padStart(2, '0')}`;
195
+ let year: string;
196
+ if (gregorianDate.era === 'BC') {
197
+ year = gregorianDate.year === 1
198
+ ? '0000'
199
+ : '-' + String(Math.abs(1 - gregorianDate.year)).padStart(6, '00');
200
+ } else {
201
+ year = String(gregorianDate.year).padStart(4, '0');
202
+ }
203
+ return `${year}-${String(gregorianDate.month).padStart(2, '0')}-${String(gregorianDate.day).padStart(2, '0')}`;
184
204
  }
185
205
 
186
206
  export function dateTimeToString(date: AnyDateTime): string {