@internationalized/date 3.5.6 → 3.7.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.
- package/LICENSE +201 -0
- package/dist/BuddhistCalendar.main.js +1 -2
- package/dist/BuddhistCalendar.main.js.map +1 -1
- package/dist/BuddhistCalendar.mjs +1 -2
- package/dist/BuddhistCalendar.module.js +1 -2
- package/dist/BuddhistCalendar.module.js.map +1 -1
- package/dist/DateFormatter.main.js.map +1 -1
- package/dist/DateFormatter.module.js.map +1 -1
- package/dist/EthiopicCalendar.main.js +2 -4
- package/dist/EthiopicCalendar.main.js.map +1 -1
- package/dist/EthiopicCalendar.mjs +2 -4
- package/dist/EthiopicCalendar.module.js +2 -4
- package/dist/EthiopicCalendar.module.js.map +1 -1
- package/dist/IndianCalendar.main.js +1 -2
- package/dist/IndianCalendar.main.js.map +1 -1
- package/dist/IndianCalendar.mjs +1 -2
- package/dist/IndianCalendar.module.js +1 -2
- package/dist/IndianCalendar.module.js.map +1 -1
- package/dist/IslamicCalendar.main.js +2 -4
- package/dist/IslamicCalendar.main.js.map +1 -1
- package/dist/IslamicCalendar.mjs +2 -4
- package/dist/IslamicCalendar.module.js +2 -4
- package/dist/IslamicCalendar.module.js.map +1 -1
- package/dist/JapaneseCalendar.main.js +1 -2
- package/dist/JapaneseCalendar.main.js.map +1 -1
- package/dist/JapaneseCalendar.mjs +1 -2
- package/dist/JapaneseCalendar.module.js +1 -2
- package/dist/JapaneseCalendar.module.js.map +1 -1
- package/dist/TaiwanCalendar.main.js +1 -2
- package/dist/TaiwanCalendar.main.js.map +1 -1
- package/dist/TaiwanCalendar.mjs +1 -2
- package/dist/TaiwanCalendar.module.js +1 -2
- package/dist/TaiwanCalendar.module.js.map +1 -1
- package/dist/conversion.main.js +1 -1
- package/dist/conversion.main.js.map +1 -1
- package/dist/conversion.mjs +1 -1
- package/dist/conversion.module.js +1 -1
- package/dist/conversion.module.js.map +1 -1
- package/dist/queries.main.js +18 -8
- package/dist/queries.main.js.map +1 -1
- package/dist/queries.mjs +18 -8
- package/dist/queries.module.js +18 -8
- package/dist/queries.module.js.map +1 -1
- package/dist/string.main.js +26 -17
- package/dist/string.main.js.map +1 -1
- package/dist/string.mjs +26 -17
- package/dist/string.module.js +26 -17
- package/dist/string.module.js.map +1 -1
- package/dist/types.d.ts +12 -14
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/DateFormatter.ts +4 -8
- package/src/conversion.ts +1 -1
- package/src/queries.ts +29 -16
- package/src/string.ts +37 -19
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
@@ -214,16 +234,14 @@ export function parseDuration(value: string): Required<DateTimeDuration> {
|
|
|
214
234
|
|
|
215
235
|
const parseDurationGroup = (
|
|
216
236
|
group: string | undefined,
|
|
217
|
-
isNegative: boolean
|
|
218
|
-
min: number,
|
|
219
|
-
max: number
|
|
237
|
+
isNegative: boolean
|
|
220
238
|
): number => {
|
|
221
239
|
if (!group) {
|
|
222
240
|
return 0;
|
|
223
241
|
}
|
|
224
242
|
try {
|
|
225
243
|
const sign = isNegative ? -1 : 1;
|
|
226
|
-
return sign *
|
|
244
|
+
return sign * Number(group.replace(',', '.'));
|
|
227
245
|
} catch {
|
|
228
246
|
throw new Error(`Invalid ISO 8601 Duration string: ${value}`);
|
|
229
247
|
}
|
|
@@ -247,13 +265,13 @@ export function parseDuration(value: string): Required<DateTimeDuration> {
|
|
|
247
265
|
}
|
|
248
266
|
|
|
249
267
|
const duration: Mutable<DateTimeDuration> = {
|
|
250
|
-
years: parseDurationGroup(match.groups?.years, isNegative
|
|
251
|
-
months: parseDurationGroup(match.groups?.months, isNegative
|
|
252
|
-
weeks: parseDurationGroup(match.groups?.weeks, isNegative
|
|
253
|
-
days: parseDurationGroup(match.groups?.days, isNegative
|
|
254
|
-
hours: parseDurationGroup(match.groups?.hours, isNegative
|
|
255
|
-
minutes: parseDurationGroup(match.groups?.minutes, isNegative
|
|
256
|
-
seconds: parseDurationGroup(match.groups?.seconds, isNegative
|
|
268
|
+
years: parseDurationGroup(match.groups?.years, isNegative),
|
|
269
|
+
months: parseDurationGroup(match.groups?.months, isNegative),
|
|
270
|
+
weeks: parseDurationGroup(match.groups?.weeks, isNegative),
|
|
271
|
+
days: parseDurationGroup(match.groups?.days, isNegative),
|
|
272
|
+
hours: parseDurationGroup(match.groups?.hours, isNegative),
|
|
273
|
+
minutes: parseDurationGroup(match.groups?.minutes, isNegative),
|
|
274
|
+
seconds: parseDurationGroup(match.groups?.seconds, isNegative)
|
|
257
275
|
};
|
|
258
276
|
|
|
259
277
|
if (duration.hours !== undefined && ((duration.hours % 1) !== 0) && (duration.minutes || duration.seconds)) {
|