@astryxdesign/core 0.7.9-canary.45a4865 → 0.7.9-canary.4d7dca6
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/dist/i18n/InternationalizationProvider.d.ts +9 -8
- package/dist/i18n/InternationalizationProvider.d.ts.map +1 -1
- package/dist/internal/calendar-system.d.ts +18 -0
- package/dist/internal/calendar-system.d.ts.map +1 -0
- package/dist/internal/calendar-system.js +19 -0
- package/dist/utils/calendarSystem.d.ts +13 -3
- package/dist/utils/calendarSystem.d.ts.map +1 -1
- package/dist/utils/calendarSystem.js +38 -4
- package/package.json +9 -4
- package/src/i18n/InternationalizationProvider.doc.mjs +3 -3
- package/src/i18n/InternationalizationProvider.tsx +9 -8
- package/src/internal/calendar-system.ts +26 -0
- package/src/utils/calendarSystem.ts +44 -4
|
@@ -66,14 +66,15 @@ export interface InternationalizationProviderProps {
|
|
|
66
66
|
dir?: 'ltr' | 'rtl';
|
|
67
67
|
/**
|
|
68
68
|
* The calendar system of this subtree, such as `'persian'` or `'hebrew'`.
|
|
69
|
-
* `Calendar` shows it, and Timestamp
|
|
70
|
-
* The date inputs show Gregorian dates. Values stay
|
|
71
|
-
* omitted, the calendar is Gregorian: a locale
|
|
72
|
-
* its default calendar nor by a `-u-ca-`
|
|
73
|
-
* `calendar` prop takes precedence. Calendars
|
|
74
|
-
* `iso8601`, `buddhist`, `roc`, and `japanese` need
|
|
75
|
-
* keeps the requested calendar; where `Temporal` is
|
|
76
|
-
* show Gregorian dates and warn once in
|
|
69
|
+
* `Calendar` shows it, and Timestamp, PowerSearch, and Lab's Schedule write
|
|
70
|
+
* their dates in it. The date inputs show Gregorian dates. Values stay
|
|
71
|
+
* Gregorian ISO dates. When omitted, the calendar is Gregorian: a locale
|
|
72
|
+
* never selects it, neither by its default calendar nor by a `-u-ca-`
|
|
73
|
+
* keyword. A component's own `calendar` prop takes precedence. Calendars
|
|
74
|
+
* other than `gregory`, `iso8601`, `buddhist`, `roc`, and `japanese` need
|
|
75
|
+
* `Temporal`. The context keeps the requested calendar; where `Temporal` is
|
|
76
|
+
* missing, these components show Gregorian dates and warn once in
|
|
77
|
+
* development.
|
|
77
78
|
*
|
|
78
79
|
* @example
|
|
79
80
|
* ```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternationalizationProvider.d.ts","sourceRoot":"","sources":["../../src/i18n/InternationalizationProvider.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAI9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EACV,MAAM,EAEN,SAAS,EACT,wBAAwB,EACzB,MAAM,SAAS,CAAC;AA4BjB,MAAM,WAAW,iCAAiC;IAChD;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACpB
|
|
1
|
+
{"version":3,"file":"InternationalizationProvider.d.ts","sourceRoot":"","sources":["../../src/i18n/InternationalizationProvider.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAU,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AAI9C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAC5D,OAAO,KAAK,EACV,MAAM,EAEN,SAAS,EACT,wBAAwB,EACzB,MAAM,SAAS,CAAC;AA4BjB,MAAM,WAAW,iCAAiC;IAChD;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,wBAAwB,CAAC;IACpC;;;;;;;;;;OAUG;IACH,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACpB;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,MAAM,EACN,QAAQ,EACR,SAAS,EACT,GAAG,EACH,QAAQ,EAAE,YAAY,EACtB,QAAQ,GACT,EAAE,iCAAiC,+BAyBnC;yBAhCe,4BAA4B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file calendar-system.ts
|
|
3
|
+
* @input The i18n calendar resolution
|
|
4
|
+
* @output `@astryxdesign/core/internal/calendar-system`: the hook that
|
|
5
|
+
* resolves the calendar a date component shows, and the helpers that name
|
|
6
|
+
* its months and days as Core's Calendar does, for Lab components
|
|
7
|
+
* @position An internal entry reserved for Astryx's own packages:
|
|
8
|
+
* undocumented, outside the public API and its compatibility promise,
|
|
9
|
+
* versioned in lockstep with Core, and allowed only in Core and Lab by the
|
|
10
|
+
* `@astryx/no-core-internal-import` lint rule. Named re-exports only.
|
|
11
|
+
*
|
|
12
|
+
* SYNC: When modified, update calendar-system.test.ts and
|
|
13
|
+
* scripts/sync-exports.js.
|
|
14
|
+
*/
|
|
15
|
+
export { useCalendarSystem } from '../i18n/useCalendarSystem.js';
|
|
16
|
+
export { calendarMonthLabelDay, calendarMonthOf, formatCalendarDate, formatCalendarDateToParts, formatCalendarInstantRange, } from '../utils/calendarSystem.js';
|
|
17
|
+
export type { CalendarSystem } from '../utils/calendarSystem.js';
|
|
18
|
+
//# sourceMappingURL=calendar-system.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-system.d.ts","sourceRoot":"","sources":["../../src/internal/calendar-system.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,yBAAyB,EACzB,0BAA0B,GAC3B,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file calendar-system.ts
|
|
5
|
+
* @input The i18n calendar resolution
|
|
6
|
+
* @output `@astryxdesign/core/internal/calendar-system`: the hook that
|
|
7
|
+
* resolves the calendar a date component shows, and the helpers that name
|
|
8
|
+
* its months and days as Core's Calendar does, for Lab components
|
|
9
|
+
* @position An internal entry reserved for Astryx's own packages:
|
|
10
|
+
* undocumented, outside the public API and its compatibility promise,
|
|
11
|
+
* versioned in lockstep with Core, and allowed only in Core and Lab by the
|
|
12
|
+
* `@astryx/no-core-internal-import` lint rule. Named re-exports only.
|
|
13
|
+
*
|
|
14
|
+
* SYNC: When modified, update calendar-system.test.ts and
|
|
15
|
+
* scripts/sync-exports.js.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export { useCalendarSystem } from "../i18n/useCalendarSystem.js";
|
|
19
|
+
export { calendarMonthLabelDay, calendarMonthOf, formatCalendarDate, formatCalendarDateToParts, formatCalendarInstantRange } from "../utils/calendarSystem.js";
|
|
@@ -67,11 +67,15 @@ export declare function calendarShiftMonths(calendar: CalendarSystem, pd: PlainD
|
|
|
67
67
|
export declare function calendarShiftYears(calendar: CalendarSystem, pd: PlainDate, n: number): PlainDate;
|
|
68
68
|
/** Whether a Gregorian date falls inside a calendar month. */
|
|
69
69
|
export declare function isInCalendarMonth(pd: PlainDate, month: CalendarMonth): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The day that names a calendar month: its middle day. In the Japanese
|
|
72
|
+
* calendar an era can start inside a month, and most days of that month then
|
|
73
|
+
* belong to the era of its middle day.
|
|
74
|
+
*/
|
|
75
|
+
export declare function calendarMonthLabelDay(month: CalendarMonth): PlainDate;
|
|
70
76
|
/**
|
|
71
77
|
* The stand-alone month and year label of a calendar month, such as
|
|
72
|
-
* "Aban 1405 AP"
|
|
73
|
-
* Japanese calendar an era can start inside a month, and most days of that
|
|
74
|
-
* month then belong to the era of its middle day.
|
|
78
|
+
* "Aban 1405 AP", named by `calendarMonthLabelDay`.
|
|
75
79
|
*/
|
|
76
80
|
export declare function formatCalendarMonthLabel(calendar: CalendarSystem, month: CalendarMonth, locale: Locale): string;
|
|
77
81
|
/**
|
|
@@ -96,6 +100,12 @@ export declare function formatCalendarDateToParts(calendar: CalendarSystem, pd:
|
|
|
96
100
|
* `options` asks for.
|
|
97
101
|
*/
|
|
98
102
|
export declare function formatCalendarInstant(calendar: CalendarSystem, instant: Date, options: Intl.DateTimeFormatOptions, locale: Locale, timeZone?: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Formats the range between two instants. Intl writes the fields that both
|
|
105
|
+
* ends share once. Where Intl names another month or day than Temporal at
|
|
106
|
+
* either end, the range writes each end in full.
|
|
107
|
+
*/
|
|
108
|
+
export declare function formatCalendarInstantRange(calendar: CalendarSystem, start: Date, end: Date, options: Intl.DateTimeFormatOptions, locale: Locale, timeZone?: string): string;
|
|
99
109
|
/**
|
|
100
110
|
* The fields of a date written in a calendar. A field gives either `year` or
|
|
101
111
|
* `era` with `eraYear`, and either `monthCode` (such as `M05L` for a leap
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendarSystem.d.ts","sourceRoot":"","sources":["../../src/utils/calendarSystem.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;A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I,EAAE,KAAK,EAAC,EAAE,iBAAiB,GAC/B,aAAa,CAef;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,aAAa,EACpB,CAAC,EAAE,MAAM,GACR,aAAa,CASf;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,cAAc,EACxB,EAAE,EAAE,SAAS,EACb,CAAC,EAAE,MAAM,GACR,SAAS,CAKX;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,cAAc,EACxB,EAAE,EAAE,SAAS,EACb,CAAC,EAAE,MAAM,GACR,SAAS,CAKX;AAED,8DAA8D;AAC9D,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,SAAS,EACb,KAAK,EAAE,aAAa,GACnB,OAAO,CAET;AAED
|
|
1
|
+
{"version":3,"file":"calendarSystem.d.ts","sourceRoot":"","sources":["../../src/utils/calendarSystem.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAe3C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,SAAS,GACT,UAAU,GACV,KAAK,GACL,UAAU,GACV,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,OAAO,GACP,QAAQ,GACR,UAAU,GACV,SAAS,GACT,eAAe,GACf,cAAc,GACd,kBAAkB,CAAC;AAsBvB,eAAO,MAAM,gBAAgB,EAExB,aAAa,CAAC,cAAc,CAAC,CAAC;AAUnC,qEAAqE;AACrE,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAEpE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc,CAEvE;AA4CD;;;;GAIG;AACH,wB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AW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,EACxB,MAAM,EAAE,kBAAkB,GACzB,SAAS,GAAG,IAAI,CAelB;AAED,sEAAsE;AACtE,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,cAAc,EACxB,EAAE,EAAE,SAAS,GACZ,MAAM,CAIR"}
|
|
@@ -245,14 +245,21 @@ export function isInCalendarMonth(pd, month) {
|
|
|
245
245
|
return plainDateIsInRange(pd, [month.start, month.end]);
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
/**
|
|
249
|
+
* The day that names a calendar month: its middle day. In the Japanese
|
|
250
|
+
* calendar an era can start inside a month, and most days of that month then
|
|
251
|
+
* belong to the era of its middle day.
|
|
252
|
+
*/
|
|
253
|
+
export function calendarMonthLabelDay(month) {
|
|
254
|
+
return plainDateAddDays(month.start, Math.floor(month.length / 2));
|
|
255
|
+
}
|
|
256
|
+
|
|
248
257
|
/**
|
|
249
258
|
* The stand-alone month and year label of a calendar month, such as
|
|
250
|
-
* "Aban 1405 AP"
|
|
251
|
-
* Japanese calendar an era can start inside a month, and most days of that
|
|
252
|
-
* month then belong to the era of its middle day.
|
|
259
|
+
* "Aban 1405 AP", named by `calendarMonthLabelDay`.
|
|
253
260
|
*/
|
|
254
261
|
export function formatCalendarMonthLabel(calendar, month, locale) {
|
|
255
|
-
return plainDateFormatStandaloneMonthYear(
|
|
262
|
+
return plainDateFormatStandaloneMonthYear(calendarMonthLabelDay(month), locale, labelCalendar(calendar));
|
|
256
263
|
}
|
|
257
264
|
|
|
258
265
|
// Intl has no month names for `iso8601`. Labels use `gregory`, which has the
|
|
@@ -352,6 +359,33 @@ function withTemporalDay(calendar, pd, parts, options, locale) {
|
|
|
352
359
|
export function formatCalendarInstant(calendar, instant, options, locale, timeZone) {
|
|
353
360
|
return instantLabel(calendar, instant, options, locale, timeZone).text;
|
|
354
361
|
}
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Formats the range between two instants. Intl writes the fields that both
|
|
365
|
+
* ends share once. Where Intl names another month or day than Temporal at
|
|
366
|
+
* either end, the range writes each end in full.
|
|
367
|
+
*/
|
|
368
|
+
export function formatCalendarInstantRange(calendar, start, end, options, locale, timeZone) {
|
|
369
|
+
const ends = [start, end].map(instant => instantLabel(calendar, instant, options, locale, timeZone));
|
|
370
|
+
const {
|
|
371
|
+
format
|
|
372
|
+
} = ends[0];
|
|
373
|
+
if (ends.every(({
|
|
374
|
+
isIntl
|
|
375
|
+
}) => isIntl)) {
|
|
376
|
+
return format.formatRange(start, end);
|
|
377
|
+
}
|
|
378
|
+
// Intl writes a range of different years as two full dates around its
|
|
379
|
+
// separator, which gives the separator to put between the two full ends.
|
|
380
|
+
const far = new Date(start.getTime() + 400 * 86_400_000);
|
|
381
|
+
const both = format.formatRange(start, far);
|
|
382
|
+
const [from, to] = [format.format(start), format.format(far)];
|
|
383
|
+
const separator = both.startsWith(from) && both.endsWith(to) ? both.slice(from.length, both.length - to.length) : ' – ';
|
|
384
|
+
const [first, last] = ends.map(({
|
|
385
|
+
text
|
|
386
|
+
}) => text);
|
|
387
|
+
return first === last ? first : `${first}${separator}${last}`;
|
|
388
|
+
}
|
|
355
389
|
function instantLabel(calendar, instant, options, locale, timeZone) {
|
|
356
390
|
const format = dateTimeFormatAtCall(locale, {
|
|
357
391
|
...options,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/core",
|
|
3
|
-
"version": "0.7.9-canary.
|
|
3
|
+
"version": "0.7.9-canary.4d7dca6",
|
|
4
4
|
"displayName": "Astryx Core",
|
|
5
5
|
"description": "The component library. Accessible, themeable React components with built-in spacing, dark mode, and StyleX styling.",
|
|
6
6
|
"author": "Meta Open Source",
|
|
@@ -843,6 +843,11 @@
|
|
|
843
843
|
"source": "./src/internal/spinner-rotor.ts",
|
|
844
844
|
"types": "./dist/internal/spinner-rotor.d.ts",
|
|
845
845
|
"default": "./dist/internal/spinner-rotor.js"
|
|
846
|
+
},
|
|
847
|
+
"./internal/calendar-system": {
|
|
848
|
+
"source": "./src/internal/calendar-system.ts",
|
|
849
|
+
"types": "./dist/internal/calendar-system.d.ts",
|
|
850
|
+
"default": "./dist/internal/calendar-system.js"
|
|
846
851
|
}
|
|
847
852
|
},
|
|
848
853
|
"files": [
|
|
@@ -875,9 +880,9 @@
|
|
|
875
880
|
"react-dom": ">=19.0.0"
|
|
876
881
|
},
|
|
877
882
|
"devDependencies": {
|
|
878
|
-
"@astryxdesign/a11y-spec": "0.7.9-canary.
|
|
879
|
-
"@astryxdesign/cli": "0.7.9-canary.
|
|
880
|
-
"@astryxdesign/interaction-harness": "0.7.9-canary.
|
|
883
|
+
"@astryxdesign/a11y-spec": "0.7.9-canary.4d7dca6",
|
|
884
|
+
"@astryxdesign/cli": "0.7.9-canary.4d7dca6",
|
|
885
|
+
"@astryxdesign/interaction-harness": "0.7.9-canary.4d7dca6",
|
|
881
886
|
"@babel/cli": "^7.29.7",
|
|
882
887
|
"@babel/core": "^7.29.7",
|
|
883
888
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -53,7 +53,7 @@ export const docs = {
|
|
|
53
53
|
{
|
|
54
54
|
guidance: true,
|
|
55
55
|
description:
|
|
56
|
-
'Set `calendar` to show `Calendar` in another calendar system and write Timestamp and
|
|
56
|
+
'Set `calendar` to show `Calendar` in another calendar system and write Timestamp, PowerSearch, and Schedule dates in it; `DateInput`, `DateRangeInput`, and `DateTimeInput` show Gregorian dates. A locale never selects the calendar: `fa-IR` shows Gregorian dates until you set `calendar="persian"`, and a `-u-ca-` keyword in `locale`, as in `th-TH-u-ca-buddhist`, keeps Gregorian dates too. Date values stay Gregorian ISO strings.',
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
guidance: false,
|
|
@@ -96,7 +96,7 @@ export const docs = {
|
|
|
96
96
|
type: "'gregory' | 'iso8601' | 'buddhist' | 'roc' | 'japanese' | 'persian' | 'indian' | 'hebrew' | 'chinese' | 'dangi' | 'coptic' | 'ethiopic' | 'ethioaa' | 'islamic-civil' | 'islamic-tbla' | 'islamic-umalqura'",
|
|
97
97
|
required: false,
|
|
98
98
|
description:
|
|
99
|
-
"Calendar system of the subtree, such as 'persian', 'hebrew', or 'buddhist'. `Calendar` shows it, and Timestamp and
|
|
99
|
+
"Calendar system of the subtree, such as 'persian', 'hebrew', or 'buddhist'. `Calendar` shows it, and Timestamp, PowerSearch, and Lab's Schedule write their dates in it. `DateInput`, `DateRangeInput`, and `DateTimeInput` show Gregorian dates. When omitted, the calendar is Gregorian: a locale never selects it, neither by its default calendar nor by a `-u-ca-` keyword. A component's own `calendar` prop takes precedence. Values stay Gregorian ISO dates. Calendars other than gregory, iso8601, buddhist, roc, and japanese need `Temporal`; the context keeps the requested calendar, and where the runtime lacks `Temporal`, these components show Gregorian dates and warn in development. Load a polyfill such as `temporal-polyfill/full/global` on the server and in the browser.",
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
102
|
name: 'children',
|
|
@@ -217,6 +217,6 @@ export const docsDense = {
|
|
|
217
217
|
overrides:
|
|
218
218
|
'sparse per-locale key overrides applied on top of shipped defaults',
|
|
219
219
|
calendar:
|
|
220
|
-
'calendar system for Calendar, Timestamp, and
|
|
220
|
+
'calendar system for Calendar, Timestamp, PowerSearch, and Schedule dates; date inputs stay Gregorian (default: gregory; a -u-ca- keyword in locale does not select it); values stay Gregorian ISO; non-Gregorian-aligned calendars need Temporal',
|
|
221
221
|
},
|
|
222
222
|
};
|
|
@@ -106,14 +106,15 @@ export interface InternationalizationProviderProps {
|
|
|
106
106
|
dir?: 'ltr' | 'rtl';
|
|
107
107
|
/**
|
|
108
108
|
* The calendar system of this subtree, such as `'persian'` or `'hebrew'`.
|
|
109
|
-
* `Calendar` shows it, and Timestamp
|
|
110
|
-
* The date inputs show Gregorian dates. Values stay
|
|
111
|
-
* omitted, the calendar is Gregorian: a locale
|
|
112
|
-
* its default calendar nor by a `-u-ca-`
|
|
113
|
-
* `calendar` prop takes precedence. Calendars
|
|
114
|
-
* `iso8601`, `buddhist`, `roc`, and `japanese` need
|
|
115
|
-
* keeps the requested calendar; where `Temporal` is
|
|
116
|
-
* show Gregorian dates and warn once in
|
|
109
|
+
* `Calendar` shows it, and Timestamp, PowerSearch, and Lab's Schedule write
|
|
110
|
+
* their dates in it. The date inputs show Gregorian dates. Values stay
|
|
111
|
+
* Gregorian ISO dates. When omitted, the calendar is Gregorian: a locale
|
|
112
|
+
* never selects it, neither by its default calendar nor by a `-u-ca-`
|
|
113
|
+
* keyword. A component's own `calendar` prop takes precedence. Calendars
|
|
114
|
+
* other than `gregory`, `iso8601`, `buddhist`, `roc`, and `japanese` need
|
|
115
|
+
* `Temporal`. The context keeps the requested calendar; where `Temporal` is
|
|
116
|
+
* missing, these components show Gregorian dates and warn once in
|
|
117
|
+
* development.
|
|
117
118
|
*
|
|
118
119
|
* @example
|
|
119
120
|
* ```
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file calendar-system.ts
|
|
5
|
+
* @input The i18n calendar resolution
|
|
6
|
+
* @output `@astryxdesign/core/internal/calendar-system`: the hook that
|
|
7
|
+
* resolves the calendar a date component shows, and the helpers that name
|
|
8
|
+
* its months and days as Core's Calendar does, for Lab components
|
|
9
|
+
* @position An internal entry reserved for Astryx's own packages:
|
|
10
|
+
* undocumented, outside the public API and its compatibility promise,
|
|
11
|
+
* versioned in lockstep with Core, and allowed only in Core and Lab by the
|
|
12
|
+
* `@astryx/no-core-internal-import` lint rule. Named re-exports only.
|
|
13
|
+
*
|
|
14
|
+
* SYNC: When modified, update calendar-system.test.ts and
|
|
15
|
+
* scripts/sync-exports.js.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export {useCalendarSystem} from '../i18n/useCalendarSystem';
|
|
19
|
+
export {
|
|
20
|
+
calendarMonthLabelDay,
|
|
21
|
+
calendarMonthOf,
|
|
22
|
+
formatCalendarDate,
|
|
23
|
+
formatCalendarDateToParts,
|
|
24
|
+
formatCalendarInstantRange,
|
|
25
|
+
} from '../utils/calendarSystem';
|
|
26
|
+
export type {CalendarSystem} from '../utils/calendarSystem';
|
|
@@ -329,11 +329,18 @@ export function isInCalendarMonth(
|
|
|
329
329
|
return plainDateIsInRange(pd, [month.start, month.end]);
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
/**
|
|
333
|
+
* The day that names a calendar month: its middle day. In the Japanese
|
|
334
|
+
* calendar an era can start inside a month, and most days of that month then
|
|
335
|
+
* belong to the era of its middle day.
|
|
336
|
+
*/
|
|
337
|
+
export function calendarMonthLabelDay(month: CalendarMonth): PlainDate {
|
|
338
|
+
return plainDateAddDays(month.start, Math.floor(month.length / 2));
|
|
339
|
+
}
|
|
340
|
+
|
|
332
341
|
/**
|
|
333
342
|
* The stand-alone month and year label of a calendar month, such as
|
|
334
|
-
* "Aban 1405 AP"
|
|
335
|
-
* Japanese calendar an era can start inside a month, and most days of that
|
|
336
|
-
* month then belong to the era of its middle day.
|
|
343
|
+
* "Aban 1405 AP", named by `calendarMonthLabelDay`.
|
|
337
344
|
*/
|
|
338
345
|
export function formatCalendarMonthLabel(
|
|
339
346
|
calendar: CalendarSystem,
|
|
@@ -341,7 +348,7 @@ export function formatCalendarMonthLabel(
|
|
|
341
348
|
locale: Locale,
|
|
342
349
|
): string {
|
|
343
350
|
return plainDateFormatStandaloneMonthYear(
|
|
344
|
-
|
|
351
|
+
calendarMonthLabelDay(month),
|
|
345
352
|
locale,
|
|
346
353
|
labelCalendar(calendar),
|
|
347
354
|
);
|
|
@@ -503,6 +510,39 @@ export function formatCalendarInstant(
|
|
|
503
510
|
return instantLabel(calendar, instant, options, locale, timeZone).text;
|
|
504
511
|
}
|
|
505
512
|
|
|
513
|
+
/**
|
|
514
|
+
* Formats the range between two instants. Intl writes the fields that both
|
|
515
|
+
* ends share once. Where Intl names another month or day than Temporal at
|
|
516
|
+
* either end, the range writes each end in full.
|
|
517
|
+
*/
|
|
518
|
+
export function formatCalendarInstantRange(
|
|
519
|
+
calendar: CalendarSystem,
|
|
520
|
+
start: Date,
|
|
521
|
+
end: Date,
|
|
522
|
+
options: Intl.DateTimeFormatOptions,
|
|
523
|
+
locale: Locale,
|
|
524
|
+
timeZone?: string,
|
|
525
|
+
): string {
|
|
526
|
+
const ends = [start, end].map(instant =>
|
|
527
|
+
instantLabel(calendar, instant, options, locale, timeZone),
|
|
528
|
+
);
|
|
529
|
+
const {format} = ends[0];
|
|
530
|
+
if (ends.every(({isIntl}) => isIntl)) {
|
|
531
|
+
return format.formatRange(start, end);
|
|
532
|
+
}
|
|
533
|
+
// Intl writes a range of different years as two full dates around its
|
|
534
|
+
// separator, which gives the separator to put between the two full ends.
|
|
535
|
+
const far = new Date(start.getTime() + 400 * 86_400_000);
|
|
536
|
+
const both = format.formatRange(start, far);
|
|
537
|
+
const [from, to] = [format.format(start), format.format(far)];
|
|
538
|
+
const separator =
|
|
539
|
+
both.startsWith(from) && both.endsWith(to)
|
|
540
|
+
? both.slice(from.length, both.length - to.length)
|
|
541
|
+
: ' – ';
|
|
542
|
+
const [first, last] = ends.map(({text}) => text);
|
|
543
|
+
return first === last ? first : `${first}${separator}${last}`;
|
|
544
|
+
}
|
|
545
|
+
|
|
506
546
|
function instantLabel(
|
|
507
547
|
calendar: CalendarSystem,
|
|
508
548
|
instant: Date,
|