@intech-software/chronera 0.1.3 → 0.1.5
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/core/local-date.d.ts +1 -0
- package/dist/core/local-date.js +1 -0
- package/dist/core/local-date.js.map +1 -1
- package/dist/format/format-pattern.js +97 -2
- package/dist/format/format-pattern.js.map +1 -1
- package/dist/format/pattern-scanner.js +9 -0
- package/dist/format/pattern-scanner.js.map +1 -1
- package/dist/holidays/countries/ae.d.ts +6 -0
- package/dist/holidays/countries/ae.js +70 -0
- package/dist/holidays/countries/ae.js.map +1 -0
- package/dist/holidays/countries/au.d.ts +6 -0
- package/dist/holidays/countries/au.js +79 -0
- package/dist/holidays/countries/au.js.map +1 -0
- package/dist/holidays/countries/cn.d.ts +6 -0
- package/dist/holidays/countries/cn.js +57 -0
- package/dist/holidays/countries/cn.js.map +1 -0
- package/dist/holidays/countries/de.d.ts +6 -0
- package/dist/holidays/countries/de.js +81 -0
- package/dist/holidays/countries/de.js.map +1 -0
- package/dist/holidays/countries/fr.d.ts +6 -0
- package/dist/holidays/countries/fr.js +97 -0
- package/dist/holidays/countries/fr.js.map +1 -0
- package/dist/holidays/countries/gb.d.ts +6 -0
- package/dist/holidays/countries/gb.js +80 -0
- package/dist/holidays/countries/gb.js.map +1 -0
- package/dist/holidays/countries/hk.d.ts +6 -0
- package/dist/holidays/countries/hk.js +87 -0
- package/dist/holidays/countries/hk.js.map +1 -0
- package/dist/holidays/countries/in.d.ts +6 -0
- package/dist/holidays/countries/in.js +52 -0
- package/dist/holidays/countries/in.js.map +1 -0
- package/dist/holidays/countries/index.d.ts +18 -0
- package/dist/holidays/countries/index.js +34 -0
- package/dist/holidays/countries/index.js.map +1 -0
- package/dist/holidays/countries/ir.d.ts +7 -0
- package/dist/holidays/countries/ir.js +93 -0
- package/dist/holidays/countries/ir.js.map +1 -0
- package/dist/holidays/countries/jp.d.ts +6 -0
- package/dist/holidays/countries/jp.js +140 -0
- package/dist/holidays/countries/jp.js.map +1 -0
- package/dist/holidays/countries/sa.d.ts +7 -0
- package/dist/holidays/countries/sa.js +56 -0
- package/dist/holidays/countries/sa.js.map +1 -0
- package/dist/holidays/countries/sg.d.ts +6 -0
- package/dist/holidays/countries/sg.js +71 -0
- package/dist/holidays/countries/sg.js.map +1 -0
- package/dist/holidays/countries/th.d.ts +6 -0
- package/dist/holidays/countries/th.js +151 -0
- package/dist/holidays/countries/th.js.map +1 -0
- package/dist/holidays/countries/tw.d.ts +6 -0
- package/dist/holidays/countries/tw.js +57 -0
- package/dist/holidays/countries/tw.js.map +1 -0
- package/dist/holidays/countries/us.d.ts +6 -0
- package/dist/holidays/countries/us.js +112 -0
- package/dist/holidays/countries/us.js.map +1 -0
- package/dist/holidays/easter.d.ts +23 -0
- package/dist/holidays/easter.js +49 -0
- package/dist/holidays/easter.js.map +1 -0
- package/dist/holidays/index.d.ts +5 -0
- package/dist/holidays/index.js +6 -0
- package/dist/holidays/index.js.map +1 -0
- package/dist/holidays/registry.d.ts +14 -0
- package/dist/holidays/registry.js +79 -0
- package/dist/holidays/registry.js.map +1 -0
- package/dist/holidays/rules/easter-rule.d.ts +5 -0
- package/dist/holidays/rules/easter-rule.js +26 -0
- package/dist/holidays/rules/easter-rule.js.map +1 -0
- package/dist/holidays/rules/fixed-rule.d.ts +5 -0
- package/dist/holidays/rules/fixed-rule.js +72 -0
- package/dist/holidays/rules/fixed-rule.js.map +1 -0
- package/dist/holidays/rules/floating-rule.d.ts +6 -0
- package/dist/holidays/rules/floating-rule.js +53 -0
- package/dist/holidays/rules/floating-rule.js.map +1 -0
- package/dist/holidays/rules/hijri-rule.d.ts +6 -0
- package/dist/holidays/rules/hijri-rule.js +44 -0
- package/dist/holidays/rules/hijri-rule.js.map +1 -0
- package/dist/holidays/rules/index.d.ts +9 -0
- package/dist/holidays/rules/index.js +26 -0
- package/dist/holidays/rules/index.js.map +1 -0
- package/dist/holidays/types.d.ts +106 -0
- package/dist/holidays/types.js +2 -0
- package/dist/holidays/types.js.map +1 -0
- package/dist/index.d.ts +8 -3
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/operations/business-days.d.ts +30 -14
- package/dist/operations/business-days.js +115 -37
- package/dist/operations/business-days.js.map +1 -1
- package/dist/operations/holidays.d.ts +15 -0
- package/dist/operations/holidays.js +36 -0
- package/dist/operations/holidays.js.map +1 -0
- package/dist/operations/timezone.d.ts +28 -0
- package/dist/operations/timezone.js +120 -0
- package/dist/operations/timezone.js.map +1 -0
- package/dist/public-types.d.ts +16 -0
- package/dist/public-types.js.map +1 -1
- package/package.json +10 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FormatInTimeZoneOptions, Instant, SameTimeZoneOptions, TimeZoneId, TimeZoneOffsetFormat, TimeZoneOffsetInfo } from "../public-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Formats an Instant or Date in the specified IANA target time zone using a pattern string.
|
|
4
|
+
*
|
|
5
|
+
* @param instant - The source Instant or JavaScript Date.
|
|
6
|
+
* @param timeZone - The canonical or valid IANA time zone identifier (e.g. "Asia/Bangkok", "America/New_York").
|
|
7
|
+
* @param pattern - An LDML pattern string (e.g. "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss XXX", "hh:mm a zzz").
|
|
8
|
+
* @param optionsOrLocale - Optional locale string or FormatInTimeZoneOptions object.
|
|
9
|
+
* @returns The formatted date/time string.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatInTimeZone(instant: Instant | Date, timeZone: TimeZoneId, pattern: string, optionsOrLocale?: string | Readonly<FormatInTimeZoneOptions>): string;
|
|
12
|
+
/**
|
|
13
|
+
* Computes the time zone offset at the given instant (or current time if omitted).
|
|
14
|
+
*/
|
|
15
|
+
export declare function getTimeZoneOffset(timeZone: TimeZoneId, instant?: Instant | Date, format?: "string"): string;
|
|
16
|
+
export declare function getTimeZoneOffset(timeZone: TimeZoneId, instant: Instant | Date | undefined, format: "minutes"): number;
|
|
17
|
+
export declare function getTimeZoneOffset(timeZone: TimeZoneId, instant: Instant | Date | undefined, format: "totalSeconds"): number;
|
|
18
|
+
export declare function getTimeZoneOffset(timeZone: TimeZoneId, instant: Instant | Date | undefined, format: "object"): TimeZoneOffsetInfo;
|
|
19
|
+
export declare function getTimeZoneOffset(timeZone: TimeZoneId, instant?: Instant | Date, format?: TimeZoneOffsetFormat): string | number | TimeZoneOffsetInfo;
|
|
20
|
+
/**
|
|
21
|
+
* Checks whether two IANA time zone identifiers are equivalent.
|
|
22
|
+
*
|
|
23
|
+
* @param tz1 - The first time zone identifier.
|
|
24
|
+
* @param tz2 - The second time zone identifier.
|
|
25
|
+
* @param options - Mode ("canonical" | "offset") and optional reference instant for offset comparison.
|
|
26
|
+
* @returns true if equivalent according to the specified mode; otherwise false.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isSameTimeZone(tz1: TimeZoneId, tz2: TimeZoneId, options?: "canonical" | "offset" | SameTimeZoneOptions): boolean;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { projectInstantToZonedFields, validateTimeZone, } from "../runtime/timezone.js";
|
|
2
|
+
import { formatWithPatternWithRegistry } from "../format/format-pattern.js";
|
|
3
|
+
import { defaultCalendarRegistry } from "../calendar/registry.js";
|
|
4
|
+
import { instantFromDate } from "../core/instant.js";
|
|
5
|
+
import { ChroneraError } from "../errors/errors.js";
|
|
6
|
+
function toInstant(input) {
|
|
7
|
+
if (input instanceof Date) {
|
|
8
|
+
return instantFromDate(input);
|
|
9
|
+
}
|
|
10
|
+
if (typeof input === "object" &&
|
|
11
|
+
input !== null &&
|
|
12
|
+
"kind" in input &&
|
|
13
|
+
"epochMilliseconds" in input &&
|
|
14
|
+
input.kind === "instant" &&
|
|
15
|
+
typeof input.epochMilliseconds === "number") {
|
|
16
|
+
return input;
|
|
17
|
+
}
|
|
18
|
+
throw new ChroneraError("CHRONERA_INVALID_DATE", "Expected a valid Instant or Date object.");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Formats an Instant or Date in the specified IANA target time zone using a pattern string.
|
|
22
|
+
*
|
|
23
|
+
* @param instant - The source Instant or JavaScript Date.
|
|
24
|
+
* @param timeZone - The canonical or valid IANA time zone identifier (e.g. "Asia/Bangkok", "America/New_York").
|
|
25
|
+
* @param pattern - An LDML pattern string (e.g. "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss XXX", "hh:mm a zzz").
|
|
26
|
+
* @param optionsOrLocale - Optional locale string or FormatInTimeZoneOptions object.
|
|
27
|
+
* @returns The formatted date/time string.
|
|
28
|
+
*/
|
|
29
|
+
export function formatInTimeZone(instant, timeZone, pattern, optionsOrLocale) {
|
|
30
|
+
validateTimeZone(timeZone);
|
|
31
|
+
const targetInstant = toInstant(instant);
|
|
32
|
+
const options = typeof optionsOrLocale === "string"
|
|
33
|
+
? { locale: optionsOrLocale }
|
|
34
|
+
: (optionsOrLocale ?? {});
|
|
35
|
+
return formatWithPatternWithRegistry(defaultCalendarRegistry, targetInstant, pattern, {
|
|
36
|
+
...options,
|
|
37
|
+
timeZone,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function getTimeZoneOffset(timeZone, instant, format) {
|
|
41
|
+
validateTimeZone(timeZone);
|
|
42
|
+
const targetInstant = instant === undefined
|
|
43
|
+
? { kind: "instant", epochMilliseconds: Date.now() }
|
|
44
|
+
: toInstant(instant);
|
|
45
|
+
const fields = projectInstantToZonedFields(targetInstant, timeZone);
|
|
46
|
+
const zonedUtcMs = Date.UTC(fields.year, fields.month - 1, fields.day, fields.hour, fields.minute, fields.second, fields.millisecond);
|
|
47
|
+
const offsetMs = zonedUtcMs - targetInstant.epochMilliseconds;
|
|
48
|
+
const minutes = Math.round(offsetMs / 60000);
|
|
49
|
+
const totalSeconds = Math.round(offsetMs / 1000);
|
|
50
|
+
const sign = minutes >= 0 ? "+" : "-";
|
|
51
|
+
const absMinutes = Math.abs(minutes);
|
|
52
|
+
const hours = Math.floor(absMinutes / 60);
|
|
53
|
+
const mins = absMinutes % 60;
|
|
54
|
+
const formatted = `${sign}${String(hours).padStart(2, "0")}:${String(mins).padStart(2, "0")}`;
|
|
55
|
+
const selectedFormat = format ?? "string";
|
|
56
|
+
if (selectedFormat === "string") {
|
|
57
|
+
return formatted;
|
|
58
|
+
}
|
|
59
|
+
if (selectedFormat === "minutes") {
|
|
60
|
+
return minutes;
|
|
61
|
+
}
|
|
62
|
+
if (selectedFormat === "totalSeconds") {
|
|
63
|
+
return totalSeconds;
|
|
64
|
+
}
|
|
65
|
+
// format === "object": determine DST
|
|
66
|
+
const janInstant = {
|
|
67
|
+
kind: "instant",
|
|
68
|
+
epochMilliseconds: Date.UTC(fields.year, 0, 1, 12, 0, 0),
|
|
69
|
+
};
|
|
70
|
+
const julInstant = {
|
|
71
|
+
kind: "instant",
|
|
72
|
+
epochMilliseconds: Date.UTC(fields.year, 6, 1, 12, 0, 0),
|
|
73
|
+
};
|
|
74
|
+
const janFields = projectInstantToZonedFields(janInstant, timeZone);
|
|
75
|
+
const julFields = projectInstantToZonedFields(julInstant, timeZone);
|
|
76
|
+
const janOffsetMs = Date.UTC(janFields.year, janFields.month - 1, janFields.day, janFields.hour, janFields.minute, janFields.second) - janInstant.epochMilliseconds;
|
|
77
|
+
const julOffsetMs = Date.UTC(julFields.year, julFields.month - 1, julFields.day, julFields.hour, julFields.minute, julFields.second) - julInstant.epochMilliseconds;
|
|
78
|
+
const standardOffsetMs = Math.min(janOffsetMs, julOffsetMs);
|
|
79
|
+
const isDst = offsetMs > standardOffsetMs && janOffsetMs !== julOffsetMs;
|
|
80
|
+
return {
|
|
81
|
+
formatted,
|
|
82
|
+
minutes,
|
|
83
|
+
totalSeconds,
|
|
84
|
+
isDst,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Checks whether two IANA time zone identifiers are equivalent.
|
|
89
|
+
*
|
|
90
|
+
* @param tz1 - The first time zone identifier.
|
|
91
|
+
* @param tz2 - The second time zone identifier.
|
|
92
|
+
* @param options - Mode ("canonical" | "offset") and optional reference instant for offset comparison.
|
|
93
|
+
* @returns true if equivalent according to the specified mode; otherwise false.
|
|
94
|
+
*/
|
|
95
|
+
export function isSameTimeZone(tz1, tz2, options) {
|
|
96
|
+
validateTimeZone(tz1);
|
|
97
|
+
validateTimeZone(tz2);
|
|
98
|
+
const mode = typeof options === "string" ? options : (options?.mode ?? "canonical");
|
|
99
|
+
if (mode === "canonical") {
|
|
100
|
+
const trimmed1 = tz1.trim();
|
|
101
|
+
const trimmed2 = tz2.trim();
|
|
102
|
+
if (trimmed1 === trimmed2)
|
|
103
|
+
return true;
|
|
104
|
+
const canonical1 = new Intl.DateTimeFormat(undefined, {
|
|
105
|
+
timeZone: trimmed1,
|
|
106
|
+
}).resolvedOptions().timeZone;
|
|
107
|
+
const canonical2 = new Intl.DateTimeFormat(undefined, {
|
|
108
|
+
timeZone: trimmed2,
|
|
109
|
+
}).resolvedOptions().timeZone;
|
|
110
|
+
return canonical1 === canonical2;
|
|
111
|
+
}
|
|
112
|
+
// mode === "offset"
|
|
113
|
+
const refInstant = typeof options === "object" && options?.instant !== undefined
|
|
114
|
+
? options.instant
|
|
115
|
+
: undefined;
|
|
116
|
+
const offset1 = getTimeZoneOffset(tz1, refInstant, "minutes");
|
|
117
|
+
const offset2 = getTimeZoneOffset(tz2, refInstant, "minutes");
|
|
118
|
+
return offset1 === offset2;
|
|
119
|
+
}
|
|
120
|
+
//# sourceMappingURL=timezone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timezone.js","sourceRoot":"","sources":["../../src/operations/timezone.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,gBAAgB,GACjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,6BAA6B,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAA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OAAO,GAAG,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IAE9D,OAAO,OAAO,KAAK,OAAO,CAAC;AAC7B,CAAC","sourcesContent":["import {\n projectInstantToZonedFields,\n validateTimeZone,\n} from \"../runtime/timezone.js\";\nimport { formatWithPatternWithRegistry } from \"../format/format-pattern.js\";\nimport { defaultCalendarRegistry } from \"../calendar/registry.js\";\nimport { instantFromDate } from \"../core/instant.js\";\nimport { ChroneraError } from \"../errors/errors.js\";\n\nimport type {\n FormatInTimeZoneOptions,\n Instant,\n SameTimeZoneOptions,\n TimeZoneId,\n TimeZoneOffsetFormat,\n TimeZoneOffsetInfo,\n} from \"../public-types.js\";\n\nfunction toInstant(input: unknown): Instant {\n if (input instanceof Date) {\n return instantFromDate(input);\n }\n if (\n typeof input === \"object\" &&\n input !== null &&\n \"kind\" in input &&\n \"epochMilliseconds\" in input &&\n (input as Record<string, unknown>).kind === \"instant\" &&\n typeof (input as Record<string, unknown>).epochMilliseconds === \"number\"\n ) {\n return input as Instant;\n }\n throw new ChroneraError(\n \"CHRONERA_INVALID_DATE\",\n \"Expected a valid Instant or Date object.\",\n );\n}\n\n/**\n * Formats an Instant or Date in the specified IANA target time zone using a pattern string.\n *\n * @param instant - The source Instant or JavaScript Date.\n * @param timeZone - The canonical or valid IANA time zone identifier (e.g. \"Asia/Bangkok\", \"America/New_York\").\n * @param pattern - An LDML pattern string (e.g. \"yyyy-MM-dd HH:mm:ss\", \"yyyy-MM-dd HH:mm:ss XXX\", \"hh:mm a zzz\").\n * @param optionsOrLocale - Optional locale string or FormatInTimeZoneOptions object.\n * @returns The formatted date/time string.\n */\nexport function formatInTimeZone(\n instant: Instant | Date,\n timeZone: TimeZoneId,\n pattern: string,\n optionsOrLocale?: string | Readonly<FormatInTimeZoneOptions>,\n): string {\n validateTimeZone(timeZone);\n const targetInstant = toInstant(instant);\n\n const options: FormatInTimeZoneOptions =\n typeof optionsOrLocale === \"string\"\n ? { locale: optionsOrLocale }\n : (optionsOrLocale ?? {});\n\n return formatWithPatternWithRegistry(\n defaultCalendarRegistry,\n targetInstant,\n pattern,\n {\n ...options,\n timeZone,\n },\n );\n}\n\n/**\n * Computes the time zone offset at the given instant (or current time if omitted).\n */\nexport function getTimeZoneOffset(\n timeZone: TimeZoneId,\n instant?: Instant | Date,\n format?: \"string\",\n): string;\nexport function getTimeZoneOffset(\n timeZone: TimeZoneId,\n instant: Instant | Date | undefined,\n format: \"minutes\",\n): number;\nexport function getTimeZoneOffset(\n timeZone: TimeZoneId,\n instant: Instant | Date | undefined,\n format: \"totalSeconds\",\n): number;\nexport function getTimeZoneOffset(\n timeZone: TimeZoneId,\n instant: Instant | Date | undefined,\n format: \"object\",\n): TimeZoneOffsetInfo;\nexport function getTimeZoneOffset(\n timeZone: TimeZoneId,\n instant?: Instant | Date,\n format?: TimeZoneOffsetFormat,\n): string | number | TimeZoneOffsetInfo;\nexport function getTimeZoneOffset(\n timeZone: TimeZoneId,\n instant?: Instant | Date,\n format?: TimeZoneOffsetFormat,\n): string | number | TimeZoneOffsetInfo {\n validateTimeZone(timeZone);\n\n const targetInstant: Instant =\n instant === undefined\n ? { kind: \"instant\", epochMilliseconds: Date.now() }\n : toInstant(instant);\n\n const fields = projectInstantToZonedFields(targetInstant, timeZone);\n const zonedUtcMs = Date.UTC(\n fields.year,\n fields.month - 1,\n fields.day,\n fields.hour,\n fields.minute,\n fields.second,\n fields.millisecond,\n );\n\n const offsetMs = zonedUtcMs - targetInstant.epochMilliseconds;\n const minutes = Math.round(offsetMs / 60000);\n const totalSeconds = Math.round(offsetMs / 1000);\n\n const sign = minutes >= 0 ? \"+\" : \"-\";\n const absMinutes = Math.abs(minutes);\n const hours = Math.floor(absMinutes / 60);\n const mins = absMinutes % 60;\n const formatted = `${sign}${String(hours).padStart(2, \"0\")}:${String(mins).padStart(2, \"0\")}`;\n\n const selectedFormat = format ?? \"string\";\n if (selectedFormat === \"string\") {\n return formatted;\n }\n if (selectedFormat === \"minutes\") {\n return minutes;\n }\n if (selectedFormat === \"totalSeconds\") {\n return totalSeconds;\n }\n\n // format === \"object\": determine DST\n const janInstant: Instant = {\n kind: \"instant\",\n epochMilliseconds: Date.UTC(fields.year, 0, 1, 12, 0, 0),\n };\n const julInstant: Instant = {\n kind: \"instant\",\n epochMilliseconds: Date.UTC(fields.year, 6, 1, 12, 0, 0),\n };\n\n const janFields = projectInstantToZonedFields(janInstant, timeZone);\n const julFields = projectInstantToZonedFields(julInstant, timeZone);\n\n const janOffsetMs =\n Date.UTC(\n janFields.year,\n janFields.month - 1,\n janFields.day,\n janFields.hour,\n janFields.minute,\n janFields.second,\n ) - janInstant.epochMilliseconds;\n\n const julOffsetMs =\n Date.UTC(\n julFields.year,\n julFields.month - 1,\n julFields.day,\n julFields.hour,\n julFields.minute,\n julFields.second,\n ) - julInstant.epochMilliseconds;\n\n const standardOffsetMs = Math.min(janOffsetMs, julOffsetMs);\n const isDst = offsetMs > standardOffsetMs && janOffsetMs !== julOffsetMs;\n\n return {\n formatted,\n minutes,\n totalSeconds,\n isDst,\n };\n}\n\n/**\n * Checks whether two IANA time zone identifiers are equivalent.\n *\n * @param tz1 - The first time zone identifier.\n * @param tz2 - The second time zone identifier.\n * @param options - Mode (\"canonical\" | \"offset\") and optional reference instant for offset comparison.\n * @returns true if equivalent according to the specified mode; otherwise false.\n */\nexport function isSameTimeZone(\n tz1: TimeZoneId,\n tz2: TimeZoneId,\n options?: \"canonical\" | \"offset\" | SameTimeZoneOptions,\n): boolean {\n validateTimeZone(tz1);\n validateTimeZone(tz2);\n\n const mode =\n typeof options === \"string\" ? options : (options?.mode ?? \"canonical\");\n\n if (mode === \"canonical\") {\n const trimmed1 = tz1.trim();\n const trimmed2 = tz2.trim();\n if (trimmed1 === trimmed2) return true;\n\n const canonical1 = new Intl.DateTimeFormat(undefined, {\n timeZone: trimmed1,\n }).resolvedOptions().timeZone;\n const canonical2 = new Intl.DateTimeFormat(undefined, {\n timeZone: trimmed2,\n }).resolvedOptions().timeZone;\n\n return canonical1 === canonical2;\n }\n\n // mode === \"offset\"\n const refInstant =\n typeof options === \"object\" && options?.instant !== undefined\n ? options.instant\n : undefined;\n\n const offset1 = getTimeZoneOffset(tz1, refInstant, \"minutes\");\n const offset2 = getTimeZoneOffset(tz2, refInstant, \"minutes\");\n\n return offset1 === offset2;\n}\n"]}
|
package/dist/public-types.d.ts
CHANGED
|
@@ -210,3 +210,19 @@ export interface ChroneraInstance {
|
|
|
210
210
|
resolvedOptions(): ResolvedChroneraOptions;
|
|
211
211
|
}
|
|
212
212
|
export type { IsoWeekFields } from "./core/iso-week.js";
|
|
213
|
+
export interface FormatInTimeZoneOptions {
|
|
214
|
+
readonly locale?: string;
|
|
215
|
+
readonly numberingSystem?: NumberingSystemId;
|
|
216
|
+
readonly calendar?: CalendarId;
|
|
217
|
+
}
|
|
218
|
+
export type TimeZoneOffsetFormat = "string" | "minutes" | "totalSeconds" | "object";
|
|
219
|
+
export interface TimeZoneOffsetInfo {
|
|
220
|
+
readonly formatted: string;
|
|
221
|
+
readonly minutes: number;
|
|
222
|
+
readonly totalSeconds: number;
|
|
223
|
+
readonly isDst: boolean;
|
|
224
|
+
}
|
|
225
|
+
export interface SameTimeZoneOptions {
|
|
226
|
+
readonly instant?: Instant | Date;
|
|
227
|
+
readonly mode?: "canonical" | "offset";
|
|
228
|
+
}
|
package/dist/public-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"public-types.js","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DayOfYearFields } from \"./core/day-of-year.js\";\nimport type {\n FiscalFields,\n FiscalOptions,\n QuarterNumber,\n} from \"./core/fiscal.js\";\nimport type { ChroneraErrorCode } from \"./errors/error-codes.js\";\nimport type { PresetName } from \"./format/presets/types.js\";\nimport type { Rfc2822Options } from \"./format/rfc2822.js\";\n\nexport type {\n ChroneraErrorCode,\n DayOfYearFields,\n FiscalFields,\n FiscalOptions,\n PresetName,\n QuarterNumber,\n Rfc2822Options,\n};\n\nexport type BuiltInCalendarId =\n | \"iso8601\"\n | \"gregory\"\n | \"buddhist\"\n | \"islamic\"\n | \"islamic-civil\"\n | \"islamic-tbla\"\n | \"islamic-umalqura\"\n | \"persian\"\n | \"hebrew\"\n | \"japanese\"\n | \"roc\"\n | \"indian\"\n | \"coptic\"\n | \"ethiopic\"\n | \"chinese\"\n | \"dangi\";\n\ntype ExtensibleIdentifier = string & Record<never, never>;\n\nexport type CalendarId = BuiltInCalendarId | ExtensibleIdentifier;\n\nexport type LocaleId = string;\nexport type TimeZoneId = string;\nexport type NumberingSystemId = string;\nexport type EraId = string;\nexport type MonthCode = `M${string}`;\n\nexport interface Instant {\n readonly kind: \"instant\";\n readonly epochMilliseconds: number;\n}\n\nexport interface LocalDate {\n readonly kind: \"local-date\";\n readonly year: number;\n readonly month: number;\n readonly day: number;\n}\n\nexport interface LocalTime {\n readonly kind: \"local-time\";\n readonly hour: number;\n readonly minute: number;\n readonly second: number;\n readonly millisecond: number;\n}\n\nexport interface LocalDateTime {\n readonly kind: \"local-date-time\";\n readonly date: LocalDate;\n readonly time: LocalTime;\n}\n\nexport interface CalendarDate {\n readonly kind: \"calendar-date\";\n readonly calendar: CalendarId;\n readonly era?: EraId;\n readonly eraYear?: number;\n readonly year: number;\n readonly monthCode: MonthCode;\n readonly month?: number;\n readonly day: number;\n}\n\nexport interface ZonedDateTime {\n readonly kind: \"zoned-date-time\";\n readonly instant: Instant;\n readonly timeZone: TimeZoneId;\n readonly calendar: CalendarId;\n}\n\nexport type FormatDateInput = LocalDate | CalendarDate | Instant | Date;\nexport type DateOrCalendarDate = LocalDate | CalendarDate;\nexport type TimeOrDateTimeOrInstant = LocalTime | LocalDateTime | Instant;\nexport type IntervalInclusivity = \"()\" | \"[]\" | \"[)\" | \"(]\";\n\nexport interface Duration {\n readonly years?: number;\n readonly months?: number;\n readonly weeks?: number;\n readonly days?: number;\n readonly hours?: number;\n readonly minutes?: number;\n readonly seconds?: number;\n readonly milliseconds?: number;\n}\n\nexport interface DateRange<TDate> {\n readonly start: TDate;\n readonly end: TDate;\n readonly startInclusive: boolean;\n readonly endInclusive: boolean;\n}\n\nexport interface CalendarConversionMetadata {\n readonly requestedCalendar: CalendarId;\n readonly resolvedCalendar: CalendarId;\n readonly engine: \"chronera\" | \"runtime-intl\" | \"custom\";\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface CalendarConversionResult {\n readonly value: CalendarDate;\n readonly metadata: CalendarConversionMetadata;\n}\n\nexport interface ChroneraIssue {\n readonly code: ChroneraErrorCode;\n readonly message: string;\n readonly path?: readonly (string | number)[];\n}\n\nexport type SafeParseResult<T> =\n | {\n readonly success: true;\n readonly value: T;\n }\n | {\n readonly success: false;\n readonly error: ChroneraIssue;\n };\n\nexport type Comparison = -1 | 0 | 1;\n\nexport interface CalendarPlugin {\n readonly id: CalendarId;\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly validFrom: LocalDate;\n readonly validTo: LocalDate;\n toIsoDate(date: CalendarDate): LocalDate;\n fromIsoDate(date: LocalDate): CalendarDate;\n validate(date: CalendarDate): readonly ChroneraIssue[];\n}\n\nexport interface ChroneraConfig {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly calendars?: readonly CalendarPlugin[];\n readonly formatterCacheSize?: number;\n}\n\nexport interface ResolvedChroneraOptions {\n readonly locale: LocaleId;\n readonly calendar: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone: TimeZoneId;\n readonly formatterCacheSize: number;\n}\n\nexport interface FormatDateBaseOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly fallback?: \"error\";\n}\n\nexport type FormatDateOptions = FormatDateBaseOptions &\n (\n | {\n readonly style?: \"numeric\" | \"short\" | \"medium\" | \"long\" | \"full\";\n readonly preset?: never;\n }\n | {\n readonly style?: never;\n readonly preset: PresetName;\n }\n );\n\nexport interface FormatTimeOptions {\n readonly locale?: LocaleId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly style?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport interface FormatDateTimeOptions extends FormatDateBaseOptions {\n readonly dateStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly timeStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport type FormatDateRangeOptions = FormatDateOptions & {\n readonly collapse?: \"auto\" | \"none\";\n};\n\nexport interface FormatRelativeOptions {\n readonly relativeTo: Instant | LocalDate;\n readonly locale?: LocaleId;\n readonly numeric?: \"always\" | \"auto\";\n readonly unit?:\n \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface PatternFormatOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface ParseLocalDateOptions {\n readonly pattern?: string;\n readonly locale?: LocaleId;\n readonly calendar?: \"gregory\" | \"iso8601\";\n readonly numberingSystem?: NumberingSystemId;\n}\n\nexport interface ParseInstantOptions {\n readonly excessFractionalSeconds?: \"reject\" | \"truncate\" | \"round\";\n}\n\nexport interface ConvertCalendarOptions {\n readonly fallback?: \"error\";\n}\n\nexport interface CalendarCapabilities {\n readonly calendar: CalendarId;\n readonly maturity:\n \"stable\" | \"experimental\" | \"runtime-dependent\" | \"planned\" | \"unsupported\";\n readonly canFormat: boolean;\n readonly canParse: boolean;\n readonly canConvertFromAbsoluteDate: boolean;\n readonly canConvertToAbsoluteDate: boolean;\n readonly canValidate: boolean;\n readonly canAddYears: boolean;\n readonly canAddMonths: boolean;\n readonly deterministic: boolean;\n readonly algorithm?: string;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface RuntimeCapabilities {\n readonly hasDateTimeFormat: boolean;\n readonly hasFormatToParts: boolean;\n readonly hasFormatRange: boolean;\n readonly hasRelativeTimeFormat: boolean;\n readonly hasLocale: boolean;\n readonly hasSupportedValuesOf: boolean;\n readonly hasTemporal: boolean;\n readonly calendars: Readonly<Record<string, boolean>>;\n readonly timeZones: Readonly<Record<string, boolean>>;\n}\n\nexport interface ChroneraInstance {\n formatDate(\n input: FormatDateInput,\n options?: Readonly<FormatDateOptions>,\n ): string;\n parseLocalDate(\n input: string,\n options?: Readonly<ParseLocalDateOptions>,\n ): LocalDate;\n convertCalendarDate(\n source: CalendarDate,\n targetCalendar: CalendarId,\n options?: Readonly<ConvertCalendarOptions>,\n ): CalendarConversionResult;\n resolvedOptions(): ResolvedChroneraOptions;\n}\n\nexport type { IsoWeekFields } from \"./core/iso-week.js\";\n"]}
|
|
1
|
+
{"version":3,"file":"public-types.js","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DayOfYearFields } from \"./core/day-of-year.js\";\nimport type {\n FiscalFields,\n FiscalOptions,\n QuarterNumber,\n} from \"./core/fiscal.js\";\nimport type { ChroneraErrorCode } from \"./errors/error-codes.js\";\nimport type { PresetName } from \"./format/presets/types.js\";\nimport type { Rfc2822Options } from \"./format/rfc2822.js\";\n\nexport type {\n ChroneraErrorCode,\n DayOfYearFields,\n FiscalFields,\n FiscalOptions,\n PresetName,\n QuarterNumber,\n Rfc2822Options,\n};\n\nexport type BuiltInCalendarId =\n | \"iso8601\"\n | \"gregory\"\n | \"buddhist\"\n | \"islamic\"\n | \"islamic-civil\"\n | \"islamic-tbla\"\n | \"islamic-umalqura\"\n | \"persian\"\n | \"hebrew\"\n | \"japanese\"\n | \"roc\"\n | \"indian\"\n | \"coptic\"\n | \"ethiopic\"\n | \"chinese\"\n | \"dangi\";\n\ntype ExtensibleIdentifier = string & Record<never, never>;\n\nexport type CalendarId = BuiltInCalendarId | ExtensibleIdentifier;\n\nexport type LocaleId = string;\nexport type TimeZoneId = string;\nexport type NumberingSystemId = string;\nexport type EraId = string;\nexport type MonthCode = `M${string}`;\n\nexport interface Instant {\n readonly kind: \"instant\";\n readonly epochMilliseconds: number;\n}\n\nexport interface LocalDate {\n readonly kind: \"local-date\";\n readonly year: number;\n readonly month: number;\n readonly day: number;\n}\n\nexport interface LocalTime {\n readonly kind: \"local-time\";\n readonly hour: number;\n readonly minute: number;\n readonly second: number;\n readonly millisecond: number;\n}\n\nexport interface LocalDateTime {\n readonly kind: \"local-date-time\";\n readonly date: LocalDate;\n readonly time: LocalTime;\n}\n\nexport interface CalendarDate {\n readonly kind: \"calendar-date\";\n readonly calendar: CalendarId;\n readonly era?: EraId;\n readonly eraYear?: number;\n readonly year: number;\n readonly monthCode: MonthCode;\n readonly month?: number;\n readonly day: number;\n}\n\nexport interface ZonedDateTime {\n readonly kind: \"zoned-date-time\";\n readonly instant: Instant;\n readonly timeZone: TimeZoneId;\n readonly calendar: CalendarId;\n}\n\nexport type FormatDateInput = LocalDate | CalendarDate | Instant | Date;\nexport type DateOrCalendarDate = LocalDate | CalendarDate;\nexport type TimeOrDateTimeOrInstant = LocalTime | LocalDateTime | Instant;\nexport type IntervalInclusivity = \"()\" | \"[]\" | \"[)\" | \"(]\";\n\nexport interface Duration {\n readonly years?: number;\n readonly months?: number;\n readonly weeks?: number;\n readonly days?: number;\n readonly hours?: number;\n readonly minutes?: number;\n readonly seconds?: number;\n readonly milliseconds?: number;\n}\n\nexport interface DateRange<TDate> {\n readonly start: TDate;\n readonly end: TDate;\n readonly startInclusive: boolean;\n readonly endInclusive: boolean;\n}\n\nexport interface CalendarConversionMetadata {\n readonly requestedCalendar: CalendarId;\n readonly resolvedCalendar: CalendarId;\n readonly engine: \"chronera\" | \"runtime-intl\" | \"custom\";\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface CalendarConversionResult {\n readonly value: CalendarDate;\n readonly metadata: CalendarConversionMetadata;\n}\n\nexport interface ChroneraIssue {\n readonly code: ChroneraErrorCode;\n readonly message: string;\n readonly path?: readonly (string | number)[];\n}\n\nexport type SafeParseResult<T> =\n | {\n readonly success: true;\n readonly value: T;\n }\n | {\n readonly success: false;\n readonly error: ChroneraIssue;\n };\n\nexport type Comparison = -1 | 0 | 1;\n\nexport interface CalendarPlugin {\n readonly id: CalendarId;\n readonly algorithm: string;\n readonly deterministic: boolean;\n readonly validFrom: LocalDate;\n readonly validTo: LocalDate;\n toIsoDate(date: CalendarDate): LocalDate;\n fromIsoDate(date: LocalDate): CalendarDate;\n validate(date: CalendarDate): readonly ChroneraIssue[];\n}\n\nexport interface ChroneraConfig {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly calendars?: readonly CalendarPlugin[];\n readonly formatterCacheSize?: number;\n}\n\nexport interface ResolvedChroneraOptions {\n readonly locale: LocaleId;\n readonly calendar: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone: TimeZoneId;\n readonly formatterCacheSize: number;\n}\n\nexport interface FormatDateBaseOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly fallback?: \"error\";\n}\n\nexport type FormatDateOptions = FormatDateBaseOptions &\n (\n | {\n readonly style?: \"numeric\" | \"short\" | \"medium\" | \"long\" | \"full\";\n readonly preset?: never;\n }\n | {\n readonly style?: never;\n readonly preset: PresetName;\n }\n );\n\nexport interface FormatTimeOptions {\n readonly locale?: LocaleId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n readonly style?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport interface FormatDateTimeOptions extends FormatDateBaseOptions {\n readonly dateStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly timeStyle?: \"short\" | \"medium\" | \"long\" | \"full\";\n readonly hourCycle?: \"h11\" | \"h12\" | \"h23\" | \"h24\";\n}\n\nexport type FormatDateRangeOptions = FormatDateOptions & {\n readonly collapse?: \"auto\" | \"none\";\n};\n\nexport interface FormatRelativeOptions {\n readonly relativeTo: Instant | LocalDate;\n readonly locale?: LocaleId;\n readonly numeric?: \"always\" | \"auto\";\n readonly unit?:\n \"second\" | \"minute\" | \"hour\" | \"day\" | \"week\" | \"month\" | \"year\";\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface PatternFormatOptions {\n readonly locale?: LocaleId;\n readonly calendar?: CalendarId;\n readonly numberingSystem?: NumberingSystemId;\n readonly timeZone?: TimeZoneId;\n}\n\nexport interface ParseLocalDateOptions {\n readonly pattern?: string;\n readonly locale?: LocaleId;\n readonly calendar?: \"gregory\" | \"iso8601\";\n readonly numberingSystem?: NumberingSystemId;\n}\n\nexport interface ParseInstantOptions {\n readonly excessFractionalSeconds?: \"reject\" | \"truncate\" | \"round\";\n}\n\nexport interface ConvertCalendarOptions {\n readonly fallback?: \"error\";\n}\n\nexport interface CalendarCapabilities {\n readonly calendar: CalendarId;\n readonly maturity:\n \"stable\" | \"experimental\" | \"runtime-dependent\" | \"planned\" | \"unsupported\";\n readonly canFormat: boolean;\n readonly canParse: boolean;\n readonly canConvertFromAbsoluteDate: boolean;\n readonly canConvertToAbsoluteDate: boolean;\n readonly canValidate: boolean;\n readonly canAddYears: boolean;\n readonly canAddMonths: boolean;\n readonly deterministic: boolean;\n readonly algorithm?: string;\n readonly dataVersion?: string;\n readonly validFrom?: LocalDate;\n readonly validTo?: LocalDate;\n}\n\nexport interface RuntimeCapabilities {\n readonly hasDateTimeFormat: boolean;\n readonly hasFormatToParts: boolean;\n readonly hasFormatRange: boolean;\n readonly hasRelativeTimeFormat: boolean;\n readonly hasLocale: boolean;\n readonly hasSupportedValuesOf: boolean;\n readonly hasTemporal: boolean;\n readonly calendars: Readonly<Record<string, boolean>>;\n readonly timeZones: Readonly<Record<string, boolean>>;\n}\n\nexport interface ChroneraInstance {\n formatDate(\n input: FormatDateInput,\n options?: Readonly<FormatDateOptions>,\n ): string;\n parseLocalDate(\n input: string,\n options?: Readonly<ParseLocalDateOptions>,\n ): LocalDate;\n convertCalendarDate(\n source: CalendarDate,\n targetCalendar: CalendarId,\n options?: Readonly<ConvertCalendarOptions>,\n ): CalendarConversionResult;\n resolvedOptions(): ResolvedChroneraOptions;\n}\n\nexport type { IsoWeekFields } from \"./core/iso-week.js\";\n\nexport interface FormatInTimeZoneOptions {\n readonly locale?: string;\n readonly numberingSystem?: NumberingSystemId;\n readonly calendar?: CalendarId;\n}\n\nexport type TimeZoneOffsetFormat =\n \"string\" | \"minutes\" | \"totalSeconds\" | \"object\";\n\nexport interface TimeZoneOffsetInfo {\n readonly formatted: string;\n readonly minutes: number;\n readonly totalSeconds: number;\n readonly isDst: boolean;\n}\n\nexport interface SameTimeZoneOptions {\n readonly instant?: Instant | Date;\n readonly mode?: \"canonical\" | \"offset\";\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intech-software/chronera",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "A universal, type-safe date, time, calendar, era, locale, and timezone toolkit for JavaScript and TypeScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"date",
|
|
@@ -53,6 +53,10 @@
|
|
|
53
53
|
"./parse": {
|
|
54
54
|
"types": "./dist/parse/index.d.ts",
|
|
55
55
|
"import": "./dist/parse/index.js"
|
|
56
|
+
},
|
|
57
|
+
"./holidays": {
|
|
58
|
+
"types": "./dist/holidays/index.d.ts",
|
|
59
|
+
"import": "./dist/holidays/index.js"
|
|
56
60
|
}
|
|
57
61
|
},
|
|
58
62
|
"files": [
|
|
@@ -98,6 +102,11 @@
|
|
|
98
102
|
"name": "Parse (@intech-software/chronera/parse)",
|
|
99
103
|
"path": "dist/parse/index.js",
|
|
100
104
|
"limit": "10 KB"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"name": "Holidays (@intech-software/chronera/holidays)",
|
|
108
|
+
"path": "dist/holidays/index.js",
|
|
109
|
+
"limit": "10 KB"
|
|
101
110
|
}
|
|
102
111
|
],
|
|
103
112
|
"publishConfig": {
|