@intech-software/chronera 0.1.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 +190 -0
- package/README.md +6644 -0
- package/dist/calendar/buddhist/adapter.d.ts +2 -0
- package/dist/calendar/buddhist/adapter.js +33 -0
- package/dist/calendar/buddhist/adapter.js.map +1 -0
- package/dist/calendar/buddhist/constants.d.ts +3 -0
- package/dist/calendar/buddhist/constants.js +14 -0
- package/dist/calendar/buddhist/constants.js.map +1 -0
- package/dist/calendar/buddhist/index.d.ts +3 -0
- package/dist/calendar/buddhist/index.js +4 -0
- package/dist/calendar/buddhist/index.js.map +1 -0
- package/dist/calendar/buddhist/validator.d.ts +4 -0
- package/dist/calendar/buddhist/validator.js +60 -0
- package/dist/calendar/buddhist/validator.js.map +1 -0
- package/dist/calendar/gregory/absolute-day.d.ts +12 -0
- package/dist/calendar/gregory/absolute-day.js +14 -0
- package/dist/calendar/gregory/absolute-day.js.map +1 -0
- package/dist/calendar/gregory/adapter.d.ts +3 -0
- package/dist/calendar/gregory/adapter.js +93 -0
- package/dist/calendar/gregory/adapter.js.map +1 -0
- package/dist/calendar/gregory/constants.d.ts +3 -0
- package/dist/calendar/gregory/constants.js +18 -0
- package/dist/calendar/gregory/constants.js.map +1 -0
- package/dist/calendar/gregory/index.d.ts +4 -0
- package/dist/calendar/gregory/index.js +5 -0
- package/dist/calendar/gregory/index.js.map +1 -0
- package/dist/calendar/gregory/leap-year.d.ts +1 -0
- package/dist/calendar/gregory/leap-year.js +2 -0
- package/dist/calendar/gregory/leap-year.js.map +1 -0
- package/dist/calendar/gregory/validator.d.ts +2 -0
- package/dist/calendar/gregory/validator.js +45 -0
- package/dist/calendar/gregory/validator.js.map +1 -0
- package/dist/calendar/hijri/civil-adapter.d.ts +12 -0
- package/dist/calendar/hijri/civil-adapter.js +132 -0
- package/dist/calendar/hijri/civil-adapter.js.map +1 -0
- package/dist/calendar/hijri/index.d.ts +3 -0
- package/dist/calendar/hijri/index.js +4 -0
- package/dist/calendar/hijri/index.js.map +1 -0
- package/dist/calendar/hijri/tabular-adapter.d.ts +4 -0
- package/dist/calendar/hijri/tabular-adapter.js +79 -0
- package/dist/calendar/hijri/tabular-adapter.js.map +1 -0
- package/dist/calendar/hijri/umm-al-qura-adapter.d.ts +4 -0
- package/dist/calendar/hijri/umm-al-qura-adapter.js +27 -0
- package/dist/calendar/hijri/umm-al-qura-adapter.js.map +1 -0
- package/dist/calendar/index.d.ts +13 -0
- package/dist/calendar/index.js +12 -0
- package/dist/calendar/index.js.map +1 -0
- package/dist/calendar/indian/adapter.d.ts +2 -0
- package/dist/calendar/indian/adapter.js +66 -0
- package/dist/calendar/indian/adapter.js.map +1 -0
- package/dist/calendar/indian/constants.d.ts +5 -0
- package/dist/calendar/indian/constants.js +43 -0
- package/dist/calendar/indian/constants.js.map +1 -0
- package/dist/calendar/indian/index.d.ts +3 -0
- package/dist/calendar/indian/index.js +4 -0
- package/dist/calendar/indian/index.js.map +1 -0
- package/dist/calendar/indian/validator.d.ts +6 -0
- package/dist/calendar/indian/validator.js +65 -0
- package/dist/calendar/indian/validator.js.map +1 -0
- package/dist/calendar/japanese/adapter.d.ts +3 -0
- package/dist/calendar/japanese/adapter.js +63 -0
- package/dist/calendar/japanese/adapter.js.map +1 -0
- package/dist/calendar/japanese/constants.d.ts +17 -0
- package/dist/calendar/japanese/constants.js +85 -0
- package/dist/calendar/japanese/constants.js.map +1 -0
- package/dist/calendar/japanese/index.d.ts +3 -0
- package/dist/calendar/japanese/index.js +4 -0
- package/dist/calendar/japanese/index.js.map +1 -0
- package/dist/calendar/japanese/validator.d.ts +5 -0
- package/dist/calendar/japanese/validator.js +76 -0
- package/dist/calendar/japanese/validator.js.map +1 -0
- package/dist/calendar/persian/adapter.d.ts +2 -0
- package/dist/calendar/persian/adapter.js +42 -0
- package/dist/calendar/persian/adapter.js.map +1 -0
- package/dist/calendar/persian/constants.d.ts +5 -0
- package/dist/calendar/persian/constants.js +43 -0
- package/dist/calendar/persian/constants.js.map +1 -0
- package/dist/calendar/persian/index.d.ts +4 -0
- package/dist/calendar/persian/index.js +5 -0
- package/dist/calendar/persian/index.js.map +1 -0
- package/dist/calendar/persian/math.d.ts +24 -0
- package/dist/calendar/persian/math.js +109 -0
- package/dist/calendar/persian/math.js.map +1 -0
- package/dist/calendar/persian/validator.d.ts +4 -0
- package/dist/calendar/persian/validator.js +52 -0
- package/dist/calendar/persian/validator.js.map +1 -0
- package/dist/calendar/registry.d.ts +9 -0
- package/dist/calendar/registry.js +119 -0
- package/dist/calendar/registry.js.map +1 -0
- package/dist/calendar/roc/adapter.d.ts +2 -0
- package/dist/calendar/roc/adapter.js +47 -0
- package/dist/calendar/roc/adapter.js.map +1 -0
- package/dist/calendar/roc/constants.d.ts +6 -0
- package/dist/calendar/roc/constants.js +34 -0
- package/dist/calendar/roc/constants.js.map +1 -0
- package/dist/calendar/roc/index.d.ts +3 -0
- package/dist/calendar/roc/index.js +4 -0
- package/dist/calendar/roc/index.js.map +1 -0
- package/dist/calendar/roc/validator.d.ts +4 -0
- package/dist/calendar/roc/validator.js +52 -0
- package/dist/calendar/roc/validator.js.map +1 -0
- package/dist/calendar/types.d.ts +34 -0
- package/dist/calendar/types.js +2 -0
- package/dist/calendar/types.js.map +1 -0
- package/dist/core/absolute-day.d.ts +8 -0
- package/dist/core/absolute-day.js +39 -0
- package/dist/core/absolute-day.js.map +1 -0
- package/dist/core/calendar-date.d.ts +11 -0
- package/dist/core/calendar-date.js +37 -0
- package/dist/core/calendar-date.js.map +1 -0
- package/dist/core/day-of-year.d.ts +16 -0
- package/dist/core/day-of-year.js +30 -0
- package/dist/core/day-of-year.js.map +1 -0
- package/dist/core/duration.d.ts +2 -0
- package/dist/core/duration.js +31 -0
- package/dist/core/duration.js.map +1 -0
- package/dist/core/fiscal.d.ts +31 -0
- package/dist/core/fiscal.js +45 -0
- package/dist/core/fiscal.js.map +1 -0
- package/dist/core/gregorian-math.d.ts +4 -0
- package/dist/core/gregorian-math.js +30 -0
- package/dist/core/gregorian-math.js.map +1 -0
- package/dist/core/instant.d.ts +6 -0
- package/dist/core/instant.js +26 -0
- package/dist/core/instant.js.map +1 -0
- package/dist/core/integer.d.ts +1 -0
- package/dist/core/integer.js +7 -0
- package/dist/core/integer.js.map +1 -0
- package/dist/core/iso-week.d.ts +19 -0
- package/dist/core/iso-week.js +41 -0
- package/dist/core/iso-week.js.map +1 -0
- package/dist/core/julian-day.d.ts +26 -0
- package/dist/core/julian-day.js +35 -0
- package/dist/core/julian-day.js.map +1 -0
- package/dist/core/local-date-time.d.ts +2 -0
- package/dist/core/local-date-time.js +15 -0
- package/dist/core/local-date-time.js.map +1 -0
- package/dist/core/local-date.d.ts +2 -0
- package/dist/core/local-date.js +22 -0
- package/dist/core/local-date.js.map +1 -0
- package/dist/core/local-time.d.ts +2 -0
- package/dist/core/local-time.js +28 -0
- package/dist/core/local-time.js.map +1 -0
- package/dist/core/range.d.ts +2 -0
- package/dist/core/range.js +9 -0
- package/dist/core/range.js.map +1 -0
- package/dist/create-chronera.d.ts +2 -0
- package/dist/create-chronera.js +59 -0
- package/dist/create-chronera.js.map +1 -0
- package/dist/errors/error-codes.d.ts +1 -0
- package/dist/errors/error-codes.js +2 -0
- package/dist/errors/error-codes.js.map +1 -0
- package/dist/errors/errors.d.ts +16 -0
- package/dist/errors/errors.js +22 -0
- package/dist/errors/errors.js.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +2 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/format/format-date-range.d.ts +2 -0
- package/dist/format/format-date-range.js +89 -0
- package/dist/format/format-date-range.js.map +1 -0
- package/dist/format/format-date-time.d.ts +2 -0
- package/dist/format/format-date-time.js +51 -0
- package/dist/format/format-date-time.js.map +1 -0
- package/dist/format/format-date.d.ts +4 -0
- package/dist/format/format-date.js +103 -0
- package/dist/format/format-date.js.map +1 -0
- package/dist/format/format-pattern.d.ts +4 -0
- package/dist/format/format-pattern.js +266 -0
- package/dist/format/format-pattern.js.map +1 -0
- package/dist/format/format-relative.d.ts +2 -0
- package/dist/format/format-relative.js +93 -0
- package/dist/format/format-relative.js.map +1 -0
- package/dist/format/format-time.d.ts +2 -0
- package/dist/format/format-time.js +48 -0
- package/dist/format/format-time.js.map +1 -0
- package/dist/format/index.d.ts +13 -0
- package/dist/format/index.js +12 -0
- package/dist/format/index.js.map +1 -0
- package/dist/format/pattern-scanner.d.ts +8 -0
- package/dist/format/pattern-scanner.js +102 -0
- package/dist/format/pattern-scanner.js.map +1 -0
- package/dist/format/presets/japanese-official.d.ts +8 -0
- package/dist/format/presets/japanese-official.js +39 -0
- package/dist/format/presets/japanese-official.js.map +1 -0
- package/dist/format/presets/taiwan-official.d.ts +6 -0
- package/dist/format/presets/taiwan-official.js +23 -0
- package/dist/format/presets/taiwan-official.js.map +1 -0
- package/dist/format/presets/thai-official.d.ts +2 -0
- package/dist/format/presets/thai-official.js +45 -0
- package/dist/format/presets/thai-official.js.map +1 -0
- package/dist/format/presets/types.d.ts +2 -0
- package/dist/format/presets/types.js +2 -0
- package/dist/format/presets/types.js.map +1 -0
- package/dist/format/presets/world-locales.d.ts +29 -0
- package/dist/format/presets/world-locales.js +330 -0
- package/dist/format/presets/world-locales.js.map +1 -0
- package/dist/format/resolve-date-input.d.ts +9 -0
- package/dist/format/resolve-date-input.js +93 -0
- package/dist/format/resolve-date-input.js.map +1 -0
- package/dist/format/rfc2822.d.ts +17 -0
- package/dist/format/rfc2822.js +59 -0
- package/dist/format/rfc2822.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/engine.d.ts +8 -0
- package/dist/internal/engine.js +11 -0
- package/dist/internal/engine.js.map +1 -0
- package/dist/locale/numbering-system.d.ts +4 -0
- package/dist/locale/numbering-system.js +133 -0
- package/dist/locale/numbering-system.js.map +1 -0
- package/dist/locale/resolve-locale.d.ts +7 -0
- package/dist/locale/resolve-locale.js +51 -0
- package/dist/locale/resolve-locale.js.map +1 -0
- package/dist/locale/types.d.ts +1 -0
- package/dist/locale/types.js +2 -0
- package/dist/locale/types.js.map +1 -0
- package/dist/operations/arithmetic.d.ts +4 -0
- package/dist/operations/arithmetic.js +13 -0
- package/dist/operations/arithmetic.js.map +1 -0
- package/dist/operations/compare.d.ts +5 -0
- package/dist/operations/compare.js +50 -0
- package/dist/operations/compare.js.map +1 -0
- package/dist/operations/convert-calendar-date.d.ts +4 -0
- package/dist/operations/convert-calendar-date.js +54 -0
- package/dist/operations/convert-calendar-date.js.map +1 -0
- package/dist/operations/day-of-year.d.ts +7 -0
- package/dist/operations/day-of-year.js +29 -0
- package/dist/operations/day-of-year.js.map +1 -0
- package/dist/operations/fiscal.d.ts +5 -0
- package/dist/operations/fiscal.js +25 -0
- package/dist/operations/fiscal.js.map +1 -0
- package/dist/operations/iso-week.d.ts +9 -0
- package/dist/operations/iso-week.js +29 -0
- package/dist/operations/iso-week.js.map +1 -0
- package/dist/operations/julian-day.d.ts +6 -0
- package/dist/operations/julian-day.js +37 -0
- package/dist/operations/julian-day.js.map +1 -0
- package/dist/operations/validate.d.ts +10 -0
- package/dist/operations/validate.js +55 -0
- package/dist/operations/validate.js.map +1 -0
- package/dist/parse/field-normalizer.d.ts +1 -0
- package/dist/parse/field-normalizer.js +5 -0
- package/dist/parse/field-normalizer.js.map +1 -0
- package/dist/parse/index.d.ts +4 -0
- package/dist/parse/index.js +4 -0
- package/dist/parse/index.js.map +1 -0
- package/dist/parse/parse-instant.d.ts +2 -0
- package/dist/parse/parse-instant.js +97 -0
- package/dist/parse/parse-instant.js.map +1 -0
- package/dist/parse/parse-local-date.d.ts +2 -0
- package/dist/parse/parse-local-date.js +31 -0
- package/dist/parse/parse-local-date.js.map +1 -0
- package/dist/parse/pattern-parser.d.ts +2 -0
- package/dist/parse/pattern-parser.js +150 -0
- package/dist/parse/pattern-parser.js.map +1 -0
- package/dist/parse/safe-parse.d.ts +3 -0
- package/dist/parse/safe-parse.js +46 -0
- package/dist/parse/safe-parse.js.map +1 -0
- package/dist/public-types.d.ts +209 -0
- package/dist/public-types.js +2 -0
- package/dist/public-types.js.map +1 -0
- package/dist/runtime/bounded-lru.d.ts +11 -0
- package/dist/runtime/bounded-lru.js +42 -0
- package/dist/runtime/bounded-lru.js.map +1 -0
- package/dist/runtime/capabilities.d.ts +5 -0
- package/dist/runtime/capabilities.js +61 -0
- package/dist/runtime/capabilities.js.map +1 -0
- package/dist/runtime/intl-date-time.d.ts +11 -0
- package/dist/runtime/intl-date-time.js +38 -0
- package/dist/runtime/intl-date-time.js.map +1 -0
- package/dist/runtime/intl-number.d.ts +7 -0
- package/dist/runtime/intl-number.js +35 -0
- package/dist/runtime/intl-number.js.map +1 -0
- package/dist/runtime/intl-relative-time.d.ts +7 -0
- package/dist/runtime/intl-relative-time.js +35 -0
- package/dist/runtime/intl-relative-time.js.map +1 -0
- package/dist/runtime/timezone.d.ts +14 -0
- package/dist/runtime/timezone.js +95 -0
- package/dist/runtime/timezone.js.map +1 -0
- package/package.json +155 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ChroneraError } from "../errors/errors.js";
|
|
2
|
+
import { instantFromDate } from "../core/instant.js";
|
|
3
|
+
import { validateAndResolveLocale } from "../locale/resolve-locale.js";
|
|
4
|
+
import { formatNumberWithSystem } from "../locale/numbering-system.js";
|
|
5
|
+
export function formatTime(input, options = {}) {
|
|
6
|
+
const localeInfo = validateAndResolveLocale(options.locale);
|
|
7
|
+
const locale = localeInfo.baseLocale;
|
|
8
|
+
const numberingSystem = options.numberingSystem ?? localeInfo.unicodeNumberingSystem;
|
|
9
|
+
const style = options.style ?? "short";
|
|
10
|
+
let timestamp;
|
|
11
|
+
let timeZone = "UTC";
|
|
12
|
+
if ("kind" in input && input.kind === "local-time") {
|
|
13
|
+
if (options.timeZone !== undefined) {
|
|
14
|
+
throw new ChroneraError("CHRONERA_INCOMPATIBLE_OPTION", "Timezone option is forbidden for local-time inputs.");
|
|
15
|
+
}
|
|
16
|
+
// Anchor to arbitrary UTC date
|
|
17
|
+
timestamp = Date.UTC(1970, 0, 1, input.hour, input.minute, input.second, input.millisecond);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
let instant;
|
|
21
|
+
if ("kind" in input && input.kind === "instant") {
|
|
22
|
+
instant = input;
|
|
23
|
+
}
|
|
24
|
+
else if (input instanceof Date) {
|
|
25
|
+
instant = instantFromDate(input);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new ChroneraError("CHRONERA_INVALID_TIME", "Expected LocalTime, Instant, or Date.");
|
|
29
|
+
}
|
|
30
|
+
timestamp = instant.epochMilliseconds;
|
|
31
|
+
timeZone = options.timeZone ?? "UTC";
|
|
32
|
+
}
|
|
33
|
+
const intlOpts = {
|
|
34
|
+
timeStyle: style,
|
|
35
|
+
timeZone,
|
|
36
|
+
...(options.hourCycle !== undefined
|
|
37
|
+
? { hourCycle: options.hourCycle }
|
|
38
|
+
: {}),
|
|
39
|
+
...(numberingSystem !== undefined ? { numberingSystem } : {}),
|
|
40
|
+
};
|
|
41
|
+
const dtf = new Intl.DateTimeFormat(locale, intlOpts);
|
|
42
|
+
let output = dtf.format(new Date(timestamp));
|
|
43
|
+
if (numberingSystem && numberingSystem !== "latn") {
|
|
44
|
+
output = formatNumberWithSystem(output, numberingSystem);
|
|
45
|
+
}
|
|
46
|
+
return output;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=format-time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-time.js","sourceRoot":"","sources":["../../src/format/format-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,M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QAAQ,IAAI,KAAK,CAAC;IACvC,CAAC;IAED,MAAM,QAAQ,GAA+B;QAC3C,SAAS,EAAE,KAAK;QAChB,QAAQ;QACR,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS;YACjC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE;YAClC,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,eAAe,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9D,CAAC;IAEF,MAAM,GAAG,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACtD,IAAI,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAE7C,IAAI,eAAe,IAAI,eAAe,KAAK,MAAM,EAAE,CAAC;QAClD,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ChroneraError } from \"../errors/errors.js\";\nimport { instantFromDate } from \"../core/instant.js\";\nimport { validateAndResolveLocale } from \"../locale/resolve-locale.js\";\nimport { formatNumberWithSystem } from \"../locale/numbering-system.js\";\n\nimport type { FormatTimeOptions, Instant, LocalTime } from \"../public-types.js\";\n\nexport function formatTime(\n input: LocalTime | Instant | Date,\n options: Readonly<FormatTimeOptions> = {},\n): string {\n const localeInfo = validateAndResolveLocale(options.locale);\n const locale = localeInfo.baseLocale;\n const numberingSystem =\n options.numberingSystem ?? localeInfo.unicodeNumberingSystem;\n const style = options.style ?? \"short\";\n\n let timestamp: number;\n let timeZone = \"UTC\";\n\n if (\"kind\" in input && input.kind === \"local-time\") {\n if (options.timeZone !== undefined) {\n throw new ChroneraError(\n \"CHRONERA_INCOMPATIBLE_OPTION\",\n \"Timezone option is forbidden for local-time inputs.\",\n );\n }\n // Anchor to arbitrary UTC date\n timestamp = Date.UTC(\n 1970,\n 0,\n 1,\n input.hour,\n input.minute,\n input.second,\n input.millisecond,\n );\n } else {\n let instant: Instant;\n if (\"kind\" in input && input.kind === \"instant\") {\n instant = input;\n } else if (input instanceof Date) {\n instant = instantFromDate(input);\n } else {\n throw new ChroneraError(\n \"CHRONERA_INVALID_TIME\",\n \"Expected LocalTime, Instant, or Date.\",\n );\n }\n timestamp = instant.epochMilliseconds;\n timeZone = options.timeZone ?? \"UTC\";\n }\n\n const intlOpts: Intl.DateTimeFormatOptions = {\n timeStyle: style,\n timeZone,\n ...(options.hourCycle !== undefined\n ? { hourCycle: options.hourCycle }\n : {}),\n ...(numberingSystem !== undefined ? { numberingSystem } : {}),\n };\n\n const dtf = new Intl.DateTimeFormat(locale, intlOpts);\n let output = dtf.format(new Date(timestamp));\n\n if (numberingSystem && numberingSystem !== \"latn\") {\n output = formatNumberWithSystem(output, numberingSystem);\n }\n\n return output;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { formatDate } from "./format-date.js";
|
|
2
|
+
export { formatTime } from "./format-time.js";
|
|
3
|
+
export { formatDateTime } from "./format-date-time.js";
|
|
4
|
+
export { formatDateRange } from "./format-date-range.js";
|
|
5
|
+
export { formatWithPattern } from "./format-pattern.js";
|
|
6
|
+
export { formatRelative } from "./format-relative.js";
|
|
7
|
+
export { formatRfc2822 } from "./rfc2822.js";
|
|
8
|
+
export { formatJapaneseOfficialPreset, formatJapaneseOfficialWithWeekdayPreset, } from "./presets/japanese-official.js";
|
|
9
|
+
export { formatTaiwanOfficialPreset } from "./presets/taiwan-official.js";
|
|
10
|
+
export { formatThaiOfficialPreset } from "./presets/thai-official.js";
|
|
11
|
+
export { formatArabicGregorianPreset, formatArabicHijriPreset, formatChineseShortPreset, formatChineseStandardPreset, formatChineseWithWeekdayPreset, formatFrenchLongPreset, formatFrenchStandardPreset, formatFrenchWithWeekdayPreset, formatGermanDinStandardPreset, formatGermanLongPreset, formatGermanWithWeekdayPreset, formatJapaneseEraShortPreset, formatJapaneseSeirekiPreset, formatSpanishLongPreset, formatSpanishStandardPreset, formatSpanishWithWeekdayPreset, formatThaiShortDatePreset, formatThaiSlashDatePreset, formatUkLongPreset, formatUkStandardPreset, formatUkWithWeekdayPreset, formatUsLongPreset, formatUsStandardPreset, formatUsWithWeekdayPreset, } from "./presets/world-locales.js";
|
|
12
|
+
export type { FormatDateBaseOptions, FormatDateInput, FormatDateOptions, FormatDateRangeOptions, FormatDateTimeOptions, FormatRelativeOptions, FormatTimeOptions, PatternFormatOptions, PresetName, } from "../public-types.js";
|
|
13
|
+
export type { Rfc2822Options } from "./rfc2822.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { formatDate } from "./format-date.js";
|
|
2
|
+
export { formatTime } from "./format-time.js";
|
|
3
|
+
export { formatDateTime } from "./format-date-time.js";
|
|
4
|
+
export { formatDateRange } from "./format-date-range.js";
|
|
5
|
+
export { formatWithPattern } from "./format-pattern.js";
|
|
6
|
+
export { formatRelative } from "./format-relative.js";
|
|
7
|
+
export { formatRfc2822 } from "./rfc2822.js";
|
|
8
|
+
export { formatJapaneseOfficialPreset, formatJapaneseOfficialWithWeekdayPreset, } from "./presets/japanese-official.js";
|
|
9
|
+
export { formatTaiwanOfficialPreset } from "./presets/taiwan-official.js";
|
|
10
|
+
export { formatThaiOfficialPreset } from "./presets/thai-official.js";
|
|
11
|
+
export { formatArabicGregorianPreset, formatArabicHijriPreset, formatChineseShortPreset, formatChineseStandardPreset, formatChineseWithWeekdayPreset, formatFrenchLongPreset, formatFrenchStandardPreset, formatFrenchWithWeekdayPreset, formatGermanDinStandardPreset, formatGermanLongPreset, formatGermanWithWeekdayPreset, formatJapaneseEraShortPreset, formatJapaneseSeirekiPreset, formatSpanishLongPreset, formatSpanishStandardPreset, formatSpanishWithWeekdayPreset, formatThaiShortDatePreset, formatThaiSlashDatePreset, formatUkLongPreset, formatUkStandardPreset, formatUkWithWeekdayPreset, formatUsLongPreset, formatUsStandardPreset, formatUsWithWeekdayPreset, } from "./presets/world-locales.js";
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/format/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EACL,4BAA4B,EAC5B,uCAAuC,GACxC,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EACL,2BAA2B,EAC3B,uBAAuB,EACvB,wBAAwB,EACxB,2BAA2B,EAC3B,8BAA8B,EAC9B,sBAAsB,EACtB,0BAA0B,EAC1B,6BAA6B,EAC7B,6BAA6B,EAC7B,sBAAsB,EACtB,6BAA6B,EAC7B,4BAA4B,EAC5B,2BAA2B,EAC3B,uBAAuB,EACvB,2BAA2B,EAC3B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC","sourcesContent":["export { formatDate } from \"./format-date.js\";\nexport { formatTime } from \"./format-time.js\";\nexport { formatDateTime } from \"./format-date-time.js\";\nexport { formatDateRange } from \"./format-date-range.js\";\nexport { formatWithPattern } from \"./format-pattern.js\";\nexport { formatRelative } from \"./format-relative.js\";\nexport { formatRfc2822 } from \"./rfc2822.js\";\nexport {\n formatJapaneseOfficialPreset,\n formatJapaneseOfficialWithWeekdayPreset,\n} from \"./presets/japanese-official.js\";\nexport { formatTaiwanOfficialPreset } from \"./presets/taiwan-official.js\";\nexport { formatThaiOfficialPreset } from \"./presets/thai-official.js\";\nexport {\n formatArabicGregorianPreset,\n formatArabicHijriPreset,\n formatChineseShortPreset,\n formatChineseStandardPreset,\n formatChineseWithWeekdayPreset,\n formatFrenchLongPreset,\n formatFrenchStandardPreset,\n formatFrenchWithWeekdayPreset,\n formatGermanDinStandardPreset,\n formatGermanLongPreset,\n formatGermanWithWeekdayPreset,\n formatJapaneseEraShortPreset,\n formatJapaneseSeirekiPreset,\n formatSpanishLongPreset,\n formatSpanishStandardPreset,\n formatSpanishWithWeekdayPreset,\n formatThaiShortDatePreset,\n formatThaiSlashDatePreset,\n formatUkLongPreset,\n formatUkStandardPreset,\n formatUkWithWeekdayPreset,\n formatUsLongPreset,\n formatUsStandardPreset,\n formatUsWithWeekdayPreset,\n} from \"./presets/world-locales.js\";\n\nexport type {\n FormatDateBaseOptions,\n FormatDateInput,\n FormatDateOptions,\n FormatDateRangeOptions,\n FormatDateTimeOptions,\n FormatRelativeOptions,\n FormatTimeOptions,\n PatternFormatOptions,\n PresetName,\n} from \"../public-types.js\";\nexport type { Rfc2822Options } from \"./rfc2822.js\";\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { ChroneraError } from "../errors/errors.js";
|
|
2
|
+
const VALID_PATTERN_TOKENS = new Set([
|
|
3
|
+
"y",
|
|
4
|
+
"yy",
|
|
5
|
+
"yyyy",
|
|
6
|
+
"M",
|
|
7
|
+
"MM",
|
|
8
|
+
"MMM",
|
|
9
|
+
"MMMM",
|
|
10
|
+
"d",
|
|
11
|
+
"dd",
|
|
12
|
+
"E",
|
|
13
|
+
"EEEE",
|
|
14
|
+
"G",
|
|
15
|
+
"GGGG",
|
|
16
|
+
"H",
|
|
17
|
+
"HH",
|
|
18
|
+
"h",
|
|
19
|
+
"hh",
|
|
20
|
+
"a",
|
|
21
|
+
"m",
|
|
22
|
+
"mm",
|
|
23
|
+
"s",
|
|
24
|
+
"ss",
|
|
25
|
+
"S",
|
|
26
|
+
"SSS",
|
|
27
|
+
"XXX",
|
|
28
|
+
"Q",
|
|
29
|
+
"QQQ",
|
|
30
|
+
"QQQQ",
|
|
31
|
+
"D",
|
|
32
|
+
"DDD",
|
|
33
|
+
"w",
|
|
34
|
+
"ww",
|
|
35
|
+
"e",
|
|
36
|
+
"ee",
|
|
37
|
+
]);
|
|
38
|
+
export function scanPattern(pattern) {
|
|
39
|
+
if (typeof pattern !== "string") {
|
|
40
|
+
throw new ChroneraError("CHRONERA_PATTERN_TOO_COMPLEX", "Pattern must be a string.");
|
|
41
|
+
}
|
|
42
|
+
if (pattern.length > 256) {
|
|
43
|
+
throw new ChroneraError("CHRONERA_PATTERN_TOO_LONG", `Pattern length ${pattern.length} exceeds maximum limit of 256 code units.`);
|
|
44
|
+
}
|
|
45
|
+
const tokens = [];
|
|
46
|
+
let i = 0;
|
|
47
|
+
while (i < pattern.length) {
|
|
48
|
+
if (tokens.length >= 64) {
|
|
49
|
+
throw new ChroneraError("CHRONERA_PATTERN_TOO_COMPLEX", "Pattern token count exceeds maximum limit of 64 tokens.");
|
|
50
|
+
}
|
|
51
|
+
const ch = pattern[i];
|
|
52
|
+
// Literal escaped in single quotes
|
|
53
|
+
if (ch === "'") {
|
|
54
|
+
i++;
|
|
55
|
+
let literal = "";
|
|
56
|
+
while (i < pattern.length) {
|
|
57
|
+
if (pattern[i] === "'") {
|
|
58
|
+
if (i + 1 < pattern.length && pattern[i + 1] === "'") {
|
|
59
|
+
literal += "'";
|
|
60
|
+
i += 2;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
i++;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
literal += pattern[i];
|
|
69
|
+
i++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
tokens.push({ type: "literal", value: literal });
|
|
73
|
+
}
|
|
74
|
+
// Letters are tokens
|
|
75
|
+
else if (/[A-Za-z]/.test(ch)) {
|
|
76
|
+
let run = ch;
|
|
77
|
+
i++;
|
|
78
|
+
while (i < pattern.length && pattern[i] === ch) {
|
|
79
|
+
run += pattern[i];
|
|
80
|
+
i++;
|
|
81
|
+
}
|
|
82
|
+
if (!VALID_PATTERN_TOKENS.has(run)) {
|
|
83
|
+
throw new ChroneraError("CHRONERA_PATTERN_TOO_COMPLEX", `Unsupported or unknown pattern token: "${run}".`);
|
|
84
|
+
}
|
|
85
|
+
tokens.push({ type: "token", symbol: run });
|
|
86
|
+
}
|
|
87
|
+
// Non-letter characters outside quotes are treated as raw literals
|
|
88
|
+
else {
|
|
89
|
+
let literal = ch;
|
|
90
|
+
i++;
|
|
91
|
+
while (i < pattern.length &&
|
|
92
|
+
pattern[i] !== "'" &&
|
|
93
|
+
!/[A-Za-z]/.test(pattern[i])) {
|
|
94
|
+
literal += pattern[i];
|
|
95
|
+
i++;
|
|
96
|
+
}
|
|
97
|
+
tokens.push({ type: "literal", value: literal });
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return tokens;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=pattern-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pattern-scanner.js","sourceRoot":"","sources":["../../src/format/pattern-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKpD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,GAAG;IACH,IAAI;IACJ,MAAM;IACN,GAAG;IACH,IAAI;IACJ,KAAK;IACL,MAAM;IACN,GAAG;IACH,IAAI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AAE,CAAC,EAC7B,CAAC;gBACD,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;gBACtB,CAAC,EAAE,CAAC;YACN,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { ChroneraError } from \"../errors/errors.js\";\n\nexport type PatternToken =\n { type: \"token\"; symbol: string } | { type: \"literal\"; value: string };\n\nconst VALID_PATTERN_TOKENS = new Set([\n \"y\",\n \"yy\",\n \"yyyy\",\n \"M\",\n \"MM\",\n \"MMM\",\n \"MMMM\",\n \"d\",\n \"dd\",\n \"E\",\n \"EEEE\",\n \"G\",\n \"GGGG\",\n \"H\",\n \"HH\",\n \"h\",\n \"hh\",\n \"a\",\n \"m\",\n \"mm\",\n \"s\",\n \"ss\",\n \"S\",\n \"SSS\",\n \"XXX\",\n \"Q\",\n \"QQQ\",\n \"QQQQ\",\n \"D\",\n \"DDD\",\n \"w\",\n \"ww\",\n \"e\",\n \"ee\",\n]);\n\nexport function scanPattern(pattern: string): PatternToken[] {\n if (typeof pattern !== \"string\") {\n throw new ChroneraError(\n \"CHRONERA_PATTERN_TOO_COMPLEX\",\n \"Pattern must be a string.\",\n );\n }\n\n if (pattern.length > 256) {\n throw new ChroneraError(\n \"CHRONERA_PATTERN_TOO_LONG\",\n `Pattern length ${pattern.length} exceeds maximum limit of 256 code units.`,\n );\n }\n\n const tokens: PatternToken[] = [];\n let i = 0;\n\n while (i < pattern.length) {\n if (tokens.length >= 64) {\n throw new ChroneraError(\n \"CHRONERA_PATTERN_TOO_COMPLEX\",\n \"Pattern token count exceeds maximum limit of 64 tokens.\",\n );\n }\n\n const ch = pattern[i]!;\n\n // Literal escaped in single quotes\n if (ch === \"'\") {\n i++;\n let literal = \"\";\n while (i < pattern.length) {\n if (pattern[i] === \"'\") {\n if (i + 1 < pattern.length && pattern[i + 1] === \"'\") {\n literal += \"'\";\n i += 2;\n } else {\n i++;\n break;\n }\n } else {\n literal += pattern[i];\n i++;\n }\n }\n tokens.push({ type: \"literal\", value: literal });\n }\n // Letters are tokens\n else if (/[A-Za-z]/.test(ch)) {\n let run = ch;\n i++;\n while (i < pattern.length && pattern[i] === ch) {\n run += pattern[i];\n i++;\n }\n if (!VALID_PATTERN_TOKENS.has(run)) {\n throw new ChroneraError(\n \"CHRONERA_PATTERN_TOO_COMPLEX\",\n `Unsupported or unknown pattern token: \"${run}\".`,\n );\n }\n tokens.push({ type: \"token\", symbol: run });\n }\n // Non-letter characters outside quotes are treated as raw literals\n else {\n let literal = ch;\n i++;\n while (\n i < pattern.length &&\n pattern[i] !== \"'\" &&\n !/[A-Za-z]/.test(pattern[i]!)\n ) {\n literal += pattern[i];\n i++;\n }\n tokens.push({ type: \"literal\", value: literal });\n }\n }\n\n return tokens;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CalendarDate, NumberingSystemId } from "../../public-types.js";
|
|
2
|
+
export interface JapaneseFormatOptions {
|
|
3
|
+
readonly numberingSystem?: NumberingSystemId;
|
|
4
|
+
readonly gannen?: boolean;
|
|
5
|
+
readonly fullWeekday?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function formatJapaneseOfficialPreset(date: CalendarDate, absoluteDay: number, options?: JapaneseFormatOptions): string;
|
|
8
|
+
export declare function formatJapaneseOfficialWithWeekdayPreset(date: CalendarDate, absoluteDay: number, options?: JapaneseFormatOptions): string;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { findJapaneseEraForAbsoluteDay, JAPANESE_WEEKDAY_SHORT, resolveJapaneseEra, } from "../../calendar/japanese/index.js";
|
|
2
|
+
import { formatNumberWithSystem } from "../../locale/numbering-system.js";
|
|
3
|
+
export function formatJapaneseOfficialPreset(date, absoluteDay, options = {}) {
|
|
4
|
+
const numberingSystem = options.numberingSystem ?? "latn";
|
|
5
|
+
const useGannen = options.gannen ?? true;
|
|
6
|
+
// Resolve era definition and eraYear
|
|
7
|
+
const isJapaneseCalendar = date.calendar === "japanese";
|
|
8
|
+
const eraDef = (isJapaneseCalendar ? resolveJapaneseEra(date.era) : undefined) ??
|
|
9
|
+
findJapaneseEraForAbsoluteDay(absoluteDay);
|
|
10
|
+
const eraYear = isJapaneseCalendar && date.eraYear !== undefined
|
|
11
|
+
? date.eraYear
|
|
12
|
+
: date.year - eraDef.offset;
|
|
13
|
+
const kanjiEra = eraDef.kanji;
|
|
14
|
+
const monthNum = date.month ?? 1;
|
|
15
|
+
const dayNum = date.day;
|
|
16
|
+
// Year representation: "元年" if eraYear === 1 and useGannen is true
|
|
17
|
+
let yearPart;
|
|
18
|
+
if (eraYear === 1 && useGannen) {
|
|
19
|
+
yearPart = "元年";
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
yearPart = `${formatNumberWithSystem(eraYear, numberingSystem)}年`;
|
|
23
|
+
}
|
|
24
|
+
const monthPart = `${formatNumberWithSystem(monthNum, numberingSystem)}月`;
|
|
25
|
+
const dayPart = `${formatNumberWithSystem(dayNum, numberingSystem)}日`;
|
|
26
|
+
return `${kanjiEra}${yearPart}${monthPart}${dayPart}`;
|
|
27
|
+
}
|
|
28
|
+
export function formatJapaneseOfficialWithWeekdayPreset(date, absoluteDay, options = {}) {
|
|
29
|
+
const base = formatJapaneseOfficialPreset(date, absoluteDay, options);
|
|
30
|
+
// Day of week from absolute day: (absoluteDay + 4) % 7
|
|
31
|
+
// 1970-01-01 was Thursday (4). (0 + 4) % 7 = 4 -> 木 (Thursday)
|
|
32
|
+
const dowIndex = (((absoluteDay + 4) % 7) + 7) % 7;
|
|
33
|
+
const weekdayShort = JAPANESE_WEEKDAY_SHORT[dowIndex];
|
|
34
|
+
if (options.fullWeekday) {
|
|
35
|
+
return `${base} ${weekdayShort}曜日`;
|
|
36
|
+
}
|
|
37
|
+
return `${base}(${weekdayShort})`;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=japanese-official.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"japanese-official.js","sourceRoot":"","sources":["../../../src/format/presets/japanese-official.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAU1E,MAAM,UAAU,4BAA4B,CAC1C,IAAkB,EAClB,WAAmB,EACnB,UAAiC,EAAE;IAEnC,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,MAAM,CAAC;IAC1D,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC;IAEzC,qCAAqC;IACrC,MAAM,kBAAkB,GAAG,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC;IACxD,MAAM,MAAM,GACV,CAAC,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC/D,6BAA6B,CAAC,WAAW,CAAC,CAAC;IAC7C,MAAM,OAAO,GACX,kBAAkB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;QAC9C,CAAC,CAAC,IAAI,CAAC,OAAO;QACd,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC;IAChC,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC;IAE9B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;IAExB,mEAAmE;IACnE,IAAI,QAAgB,CAAC;IACrB,IAAI,OAAO,KAAK,CAAC,IAAI,SAAS,EAAE,CAAC;QAC/B,QAAQ,GAAG,IAAI,CAAC;IAClB,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,GAAG,sBAAsB,CAAC,OAAO,EAAE,eAAe,CAAC,GAAG,CAAC;IACpE,CAAC;IAED,MAAM,SAAS,GAAG,GAAG,sBAAsB,CAAC,QAAQ,EAAE,eAAe,CAAC,GAAG,CAAC;IAC1E,MAAM,OAAO,GAAG,GAAG,sBAAsB,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,CAAC;IAEtE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,EAAE,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,uCAAuC,CACrD,IAAkB,EAClB,WAAmB,EACnB,UAAiC,EAAE;IAEnC,MAAM,IAAI,GAAG,4BAA4B,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IACtE,uDAAuD;IACvD,+DAA+D;IAC/D,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACnD,MAAM,YAAY,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAEtD,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,OAAO,GAAG,IAAI,IAAI,YAAY,IAAI,CAAC;IACrC,CAAC;IACD,OAAO,GAAG,IAAI,IAAI,YAAY,GAAG,CAAC;AACpC,CAAC","sourcesContent":["import {\n findJapaneseEraForAbsoluteDay,\n JAPANESE_WEEKDAY_SHORT,\n resolveJapaneseEra,\n} from \"../../calendar/japanese/index.js\";\nimport { formatNumberWithSystem } from \"../../locale/numbering-system.js\";\n\nimport type { CalendarDate, NumberingSystemId } from \"../../public-types.js\";\n\nexport interface JapaneseFormatOptions {\n readonly numberingSystem?: NumberingSystemId;\n readonly gannen?: boolean; // Default true: eraYear 1 -> 元年\n readonly fullWeekday?: boolean; // Default false: (水), true: 水曜日\n}\n\nexport function formatJapaneseOfficialPreset(\n date: CalendarDate,\n absoluteDay: number,\n options: JapaneseFormatOptions = {},\n): string {\n const numberingSystem = options.numberingSystem ?? \"latn\";\n const useGannen = options.gannen ?? true;\n\n // Resolve era definition and eraYear\n const isJapaneseCalendar = date.calendar === \"japanese\";\n const eraDef =\n (isJapaneseCalendar ? resolveJapaneseEra(date.era) : undefined) ??\n findJapaneseEraForAbsoluteDay(absoluteDay);\n const eraYear =\n isJapaneseCalendar && date.eraYear !== undefined\n ? date.eraYear\n : date.year - eraDef.offset;\n const kanjiEra = eraDef.kanji;\n\n const monthNum = date.month ?? 1;\n const dayNum = date.day;\n\n // Year representation: \"元年\" if eraYear === 1 and useGannen is true\n let yearPart: string;\n if (eraYear === 1 && useGannen) {\n yearPart = \"元年\";\n } else {\n yearPart = `${formatNumberWithSystem(eraYear, numberingSystem)}年`;\n }\n\n const monthPart = `${formatNumberWithSystem(monthNum, numberingSystem)}月`;\n const dayPart = `${formatNumberWithSystem(dayNum, numberingSystem)}日`;\n\n return `${kanjiEra}${yearPart}${monthPart}${dayPart}`;\n}\n\nexport function formatJapaneseOfficialWithWeekdayPreset(\n date: CalendarDate,\n absoluteDay: number,\n options: JapaneseFormatOptions = {},\n): string {\n const base = formatJapaneseOfficialPreset(date, absoluteDay, options);\n // Day of week from absolute day: (absoluteDay + 4) % 7\n // 1970-01-01 was Thursday (4). (0 + 4) % 7 = 4 -> 木 (Thursday)\n const dowIndex = (((absoluteDay + 4) % 7) + 7) % 7;\n const weekdayShort = JAPANESE_WEEKDAY_SHORT[dowIndex];\n\n if (options.fullWeekday) {\n return `${base} ${weekdayShort}曜日`;\n }\n return `${base}(${weekdayShort})`;\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CalendarDate, NumberingSystemId } from "../../public-types.js";
|
|
2
|
+
export interface TaiwanFormatOptions {
|
|
3
|
+
readonly numberingSystem?: NumberingSystemId;
|
|
4
|
+
readonly weekday?: "none" | "short" | "full";
|
|
5
|
+
}
|
|
6
|
+
export declare function formatTaiwanOfficialPreset(date: CalendarDate, absoluteDay: number, options?: TaiwanFormatOptions): string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ROC_OFFSET, TAIWAN_WEEKDAY_NAMES, TAIWAN_WEEKDAY_SHORT, } from "../../calendar/roc/index.js";
|
|
2
|
+
import { formatNumberWithSystem } from "../../locale/numbering-system.js";
|
|
3
|
+
export function formatTaiwanOfficialPreset(date, absoluteDay, options = {}) {
|
|
4
|
+
const numberingSystem = options.numberingSystem ?? "latn";
|
|
5
|
+
const weekdayMode = options.weekday ?? "none";
|
|
6
|
+
// Calculate ROC year
|
|
7
|
+
const rocYear = date.calendar === "roc" ? date.year : date.year - ROC_OFFSET;
|
|
8
|
+
const monthNum = date.month ?? 1;
|
|
9
|
+
const dayNum = date.day;
|
|
10
|
+
const yearPart = `${formatNumberWithSystem(rocYear, numberingSystem)}年`;
|
|
11
|
+
const monthPart = `${formatNumberWithSystem(monthNum, numberingSystem)}月`;
|
|
12
|
+
const dayPart = `${formatNumberWithSystem(dayNum, numberingSystem)}日`;
|
|
13
|
+
const base = `民國${yearPart}${monthPart}${dayPart}`;
|
|
14
|
+
if (weekdayMode === "none") {
|
|
15
|
+
return base;
|
|
16
|
+
}
|
|
17
|
+
const dowIndex = (((absoluteDay + 4) % 7) + 7) % 7;
|
|
18
|
+
if (weekdayMode === "full") {
|
|
19
|
+
return `${base} ${TAIWAN_WEEKDAY_NAMES[dowIndex]}`;
|
|
20
|
+
}
|
|
21
|
+
return `${base}(${TAIWAN_WEEKDAY_SHORT[dowIndex]})`;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=taiwan-official.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taiwan-official.js","sourceRoot":"","sources":["../../../src/format/presets/taiwan-official.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CA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N_WEEKDAY_NAMES,\n TAIWAN_WEEKDAY_SHORT,\n} from \"../../calendar/roc/index.js\";\nimport { formatNumberWithSystem } from \"../../locale/numbering-system.js\";\n\nimport type { CalendarDate, NumberingSystemId } from \"../../public-types.js\";\n\nexport interface TaiwanFormatOptions {\n readonly numberingSystem?: NumberingSystemId;\n readonly weekday?: \"none\" | \"short\" | \"full\"; // Default \"none\"\n}\n\nexport function formatTaiwanOfficialPreset(\n date: CalendarDate,\n absoluteDay: number,\n options: TaiwanFormatOptions = {},\n): string {\n const numberingSystem = options.numberingSystem ?? \"latn\";\n const weekdayMode = options.weekday ?? \"none\";\n\n // Calculate ROC year\n const rocYear = date.calendar === \"roc\" ? date.year : date.year - ROC_OFFSET;\n const monthNum = date.month ?? 1;\n const dayNum = date.day;\n\n const yearPart = `${formatNumberWithSystem(rocYear, numberingSystem)}年`;\n const monthPart = `${formatNumberWithSystem(monthNum, numberingSystem)}月`;\n const dayPart = `${formatNumberWithSystem(dayNum, numberingSystem)}日`;\n\n const base = `民國${yearPart}${monthPart}${dayPart}`;\n\n if (weekdayMode === \"none\") {\n return base;\n }\n\n const dowIndex = (((absoluteDay + 4) % 7) + 7) % 7;\n if (weekdayMode === \"full\") {\n return `${base} ${TAIWAN_WEEKDAY_NAMES[dowIndex]}`;\n }\n return `${base}(${TAIWAN_WEEKDAY_SHORT[dowIndex]})`;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { CalendarDate, NumberingSystemId } from "../../public-types.js";
|
|
2
|
+
export declare function formatThaiOfficialPreset(date: CalendarDate, preset: "thai-official-date" | "thai-official-date-with-weekday", absoluteDay: number, numberingSystem?: NumberingSystemId): string;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { formatNumberWithSystem } from "../../locale/numbering-system.js";
|
|
2
|
+
import { ChroneraError } from "../../errors/errors.js";
|
|
3
|
+
const THAI_MONTH_NAMES = [
|
|
4
|
+
"",
|
|
5
|
+
"มกราคม",
|
|
6
|
+
"กุมภาพันธ์",
|
|
7
|
+
"มีนาคม",
|
|
8
|
+
"เมษายน",
|
|
9
|
+
"พฤษภาคม",
|
|
10
|
+
"มิถุนายน",
|
|
11
|
+
"กรกฎาคม",
|
|
12
|
+
"สิงหาคม",
|
|
13
|
+
"กันยายน",
|
|
14
|
+
"ตุลาคม",
|
|
15
|
+
"พฤศจิกายน",
|
|
16
|
+
"ธันวาคม",
|
|
17
|
+
];
|
|
18
|
+
// Day 0 is 1970-01-01 (Thursday)
|
|
19
|
+
const THAI_WEEKDAY_NAMES_FROM_MOD7 = [
|
|
20
|
+
"วันพฤหัสบดี", // 0
|
|
21
|
+
"วันศุกร์", // 1
|
|
22
|
+
"วันเสาร์", // 2
|
|
23
|
+
"วันอาทิตย์", // 3
|
|
24
|
+
"วันจันทร์", // 4
|
|
25
|
+
"วันอังคาร", // 5
|
|
26
|
+
"วันพุธ", // 6
|
|
27
|
+
];
|
|
28
|
+
export function formatThaiOfficialPreset(date, preset, absoluteDay, numberingSystem = "latn") {
|
|
29
|
+
// Calendar must be buddhist or be convertible
|
|
30
|
+
const beYear = date.calendar === "buddhist" ? date.year : date.year + 543;
|
|
31
|
+
const month = date.month ?? Number.parseInt(date.monthCode.slice(1), 10);
|
|
32
|
+
const monthName = THAI_MONTH_NAMES[month];
|
|
33
|
+
if (!monthName) {
|
|
34
|
+
throw new ChroneraError("CHRONERA_INVALID_DATE", `Invalid month ${month} for Thai official date formatting.`);
|
|
35
|
+
}
|
|
36
|
+
const dayStr = formatNumberWithSystem(date.day, numberingSystem);
|
|
37
|
+
const yearStr = formatNumberWithSystem(beYear, numberingSystem);
|
|
38
|
+
if (preset === "thai-official-date") {
|
|
39
|
+
return `วันที่ ${dayStr} ${monthName} พ.ศ. ${yearStr}`;
|
|
40
|
+
}
|
|
41
|
+
const mod7 = ((absoluteDay % 7) + 7) % 7;
|
|
42
|
+
const weekdayName = THAI_WEEKDAY_NAMES_FROM_MOD7[mod7];
|
|
43
|
+
return `${weekdayName}ที่ ${dayStr} ${monthName} พ.ศ. ${yearStr}`;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=thai-official.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thai-official.js","sourceRoot":"","sources":["../../../src/format/presets/thai-official.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIvD,MAAM,gBAAgB,GAAsB;IAC1C,EAAE;IACF,QAAQ;IACR,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,UAAU;IACV,SAAS;IACT,SAAS;IACT,SAAS;IACT,QAAQ;IACR,WAAW;IACX,SAAS;CACV,CAAC;AAEF,iCAAiC;AACjC,MAAM,4BAA4B,GAAsB;IACtD,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,IAAI;IAChB,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE,IAAI;IAClB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,QAAQ,EAAE,IAAI;CACf,CAAC;AAEF,MAAM,UAAU,wBAAwB,CACtC,IAAkB,EAClB,MAAgE,EAChE,WAAmB,EACnB,kBAAqC,MAAM;IAE3C,8CAA8C;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;IAC1E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEzE,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,aAAa,CACrB,uBAAuB,EACvB,iBAAiB,KAAK,qCAAqC,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,sBAAsB,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACjE,MAAM,OAAO,GAAG,sBAAsB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAEhE,IAAI,MAAM,KAAK,oBAAoB,EAAE,CAAC;QACpC,OAAO,UAAU,MAAM,IAAI,SAAS,SAAS,OAAO,EAAE,CAAC;IACzD,CAAC;IAED,MAAM,IAAI,GAAG,CAAC,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,WAAW,GAAG,4BAA4B,CAAC,IAAI,CAAE,CAAC;IACxD,OAAO,GAAG,WAAW,OAAO,MAAM,IAAI,SAAS,SAAS,OAAO,EAAE,CAAC;AACpE,CAAC","sourcesContent":["import { formatNumberWithSystem } from \"../../locale/numbering-system.js\";\nimport { ChroneraError } from \"../../errors/errors.js\";\n\nimport type { CalendarDate, NumberingSystemId } from \"../../public-types.js\";\n\nconst THAI_MONTH_NAMES: readonly string[] = [\n \"\",\n \"มกราคม\",\n \"กุมภาพันธ์\",\n \"มีนาคม\",\n \"เมษายน\",\n \"พฤษภาคม\",\n \"มิถุนายน\",\n \"กรกฎาคม\",\n \"สิงหาคม\",\n \"กันยายน\",\n \"ตุลาคม\",\n \"พฤศจิกายน\",\n \"ธันวาคม\",\n];\n\n// Day 0 is 1970-01-01 (Thursday)\nconst THAI_WEEKDAY_NAMES_FROM_MOD7: readonly string[] = [\n \"วันพฤหัสบดี\", // 0\n \"วันศุกร์\", // 1\n \"วันเสาร์\", // 2\n \"วันอาทิตย์\", // 3\n \"วันจันทร์\", // 4\n \"วันอังคาร\", // 5\n \"วันพุธ\", // 6\n];\n\nexport function formatThaiOfficialPreset(\n date: CalendarDate,\n preset: \"thai-official-date\" | \"thai-official-date-with-weekday\",\n absoluteDay: number,\n numberingSystem: NumberingSystemId = \"latn\",\n): string {\n // Calendar must be buddhist or be convertible\n const beYear = date.calendar === \"buddhist\" ? date.year : date.year + 543;\n const month = date.month ?? Number.parseInt(date.monthCode.slice(1), 10);\n\n const monthName = THAI_MONTH_NAMES[month];\n if (!monthName) {\n throw new ChroneraError(\n \"CHRONERA_INVALID_DATE\",\n `Invalid month ${month} for Thai official date formatting.`,\n );\n }\n\n const dayStr = formatNumberWithSystem(date.day, numberingSystem);\n const yearStr = formatNumberWithSystem(beYear, numberingSystem);\n\n if (preset === \"thai-official-date\") {\n return `วันที่ ${dayStr} ${monthName} พ.ศ. ${yearStr}`;\n }\n\n const mod7 = ((absoluteDay % 7) + 7) % 7;\n const weekdayName = THAI_WEEKDAY_NAMES_FROM_MOD7[mod7]!;\n return `${weekdayName}ที่ ${dayStr} ${monthName} พ.ศ. ${yearStr}`;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export type PresetName = "thai-official-date" | "thai-official-date-with-weekday" | "thai-short-date" | "thai-slash-date" | "japanese-official" | "japanese-official-with-weekday" | "japanese-seireki" | "japanese-era-short" | "taiwan-official" | "us-standard" | "us-long" | "us-with-weekday" | "uk-standard" | "uk-long" | "uk-with-weekday" | "german-din-standard" | "german-long" | "german-with-weekday" | "french-standard" | "french-long" | "french-with-weekday" | "chinese-standard" | "chinese-with-weekday" | "chinese-short" | "spanish-standard" | "spanish-long" | "spanish-with-weekday" | "arabic-gregorian" | "arabic-hijri";
|
|
2
|
+
export type ThaiPresetName = "thai-official-date" | "thai-official-date-with-weekday" | "thai-short-date" | "thai-slash-date";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/format/presets/types.ts"],"names":[],"mappings":"","sourcesContent":["export type PresetName =\n | \"thai-official-date\"\n | \"thai-official-date-with-weekday\"\n | \"thai-short-date\"\n | \"thai-slash-date\"\n | \"japanese-official\"\n | \"japanese-official-with-weekday\"\n | \"japanese-seireki\"\n | \"japanese-era-short\"\n | \"taiwan-official\"\n | \"us-standard\"\n | \"us-long\"\n | \"us-with-weekday\"\n | \"uk-standard\"\n | \"uk-long\"\n | \"uk-with-weekday\"\n | \"german-din-standard\"\n | \"german-long\"\n | \"german-with-weekday\"\n | \"french-standard\"\n | \"french-long\"\n | \"french-with-weekday\"\n | \"chinese-standard\"\n | \"chinese-with-weekday\"\n | \"chinese-short\"\n | \"spanish-standard\"\n | \"spanish-long\"\n | \"spanish-with-weekday\"\n | \"arabic-gregorian\"\n | \"arabic-hijri\";\n\nexport type ThaiPresetName =\n | \"thai-official-date\"\n | \"thai-official-date-with-weekday\"\n | \"thai-short-date\"\n | \"thai-slash-date\";\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { CalendarDate, NumberingSystemId } from "../../public-types.js";
|
|
2
|
+
export interface WorldPresetOptions {
|
|
3
|
+
readonly numberingSystem?: NumberingSystemId;
|
|
4
|
+
}
|
|
5
|
+
export declare const AR_WEEKDAYS: readonly ["الأحد", "الاثنين", "الثلاثاء", "الأربعاء", "الخميس", "الجمعة", "السبت"];
|
|
6
|
+
export declare function formatUsStandardPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
7
|
+
export declare function formatUsLongPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
8
|
+
export declare function formatUsWithWeekdayPreset(date: CalendarDate, absDay: number, options?: WorldPresetOptions): string;
|
|
9
|
+
export declare function formatUkStandardPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
10
|
+
export declare function formatUkLongPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
11
|
+
export declare function formatUkWithWeekdayPreset(date: CalendarDate, absDay: number, options?: WorldPresetOptions): string;
|
|
12
|
+
export declare function formatGermanDinStandardPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
13
|
+
export declare function formatGermanLongPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
14
|
+
export declare function formatGermanWithWeekdayPreset(date: CalendarDate, absDay: number, options?: WorldPresetOptions): string;
|
|
15
|
+
export declare function formatFrenchStandardPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
16
|
+
export declare function formatFrenchLongPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
17
|
+
export declare function formatFrenchWithWeekdayPreset(date: CalendarDate, absDay: number, options?: WorldPresetOptions): string;
|
|
18
|
+
export declare function formatSpanishStandardPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
19
|
+
export declare function formatSpanishLongPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
20
|
+
export declare function formatSpanishWithWeekdayPreset(date: CalendarDate, absDay: number, options?: WorldPresetOptions): string;
|
|
21
|
+
export declare function formatChineseStandardPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
22
|
+
export declare function formatChineseWithWeekdayPreset(date: CalendarDate, absDay: number, options?: WorldPresetOptions): string;
|
|
23
|
+
export declare function formatChineseShortPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
24
|
+
export declare function formatArabicGregorianPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
25
|
+
export declare function formatArabicHijriPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
26
|
+
export declare function formatJapaneseSeirekiPreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
27
|
+
export declare function formatJapaneseEraShortPreset(date: CalendarDate, absDay: number, _options?: WorldPresetOptions): string;
|
|
28
|
+
export declare function formatThaiShortDatePreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|
|
29
|
+
export declare function formatThaiSlashDatePreset(date: CalendarDate, _absDay: number, options?: WorldPresetOptions): string;
|