@bessemer/cornerstone 0.5.92 → 0.5.93

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.
@@ -6,6 +6,9 @@ import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
6
6
  import Zod from 'zod';
7
7
  import { Duration, DurationLike } from '@bessemer/cornerstone/temporal/duration';
8
8
  import { TimeUnit } from '@bessemer/cornerstone/temporal/chrono';
9
+ import { Locale } from '@bessemer/cornerstone/intl/locale';
10
+ import { DateTimeFormatOptions } from '@bessemer/cornerstone/temporal/plain-date-time';
11
+ import { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id';
9
12
  export type Instant = Temporal.Instant;
10
13
  export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"instant">;
11
14
  export type InstantLiteral = NominalType<string, typeof Namespace>;
@@ -30,9 +33,9 @@ export declare const SchemaLiteral: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<
30
33
  export declare const SchemaInstance: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<Temporal.Instant, string>>;
31
34
  export declare const isInstant: (value: unknown) => value is Instant;
32
35
  export declare const now: (clock?: {
33
- readonly zone: import("./time-zone-id").TimeZoneId;
36
+ readonly zone: TimeZoneId;
34
37
  instant(): Instant;
35
- withZone(zone: import("./time-zone-id").TimeZoneId): import("@bessemer/cornerstone/temporal/clock").Clock;
38
+ withZone(zone: TimeZoneId): import("@bessemer/cornerstone/temporal/clock").Clock;
36
39
  }) => Instant;
37
40
  export declare const add: (element: InstantLike, duration: DurationLike) => Instant;
38
41
  export declare const subtract: (element: InstantLike, duration: DurationLike) => Instant;
@@ -43,4 +46,5 @@ export declare function isEqual(element: InstantLike | null, other: InstantLike
43
46
  export declare function isEqual(element: InstantLike | undefined, other: InstantLike | undefined): boolean;
44
47
  export declare const isBefore: (element: InstantLike, other: InstantLike) => boolean;
45
48
  export declare const isAfter: (element: InstantLike, other: InstantLike) => boolean;
49
+ export declare const format: (element: InstantLike, timeZone: TimeZoneId, locale: Locale, options: DateTimeFormatOptions) => string;
46
50
  //# sourceMappingURL=instant.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"instant.d.ts","sourceRoot":"","sources":["../../src/temporal/instant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAsB,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAwB,MAAM,yCAAyC,CAAA;AACtG,OAAO,EAAgC,QAAQ,EAAE,MAAM,uCAAuC,CAAA;AAI9F,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAA;AACtC,eAAO,MAAM,SAAS,2EAAuB,CAAA;AAC7C,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAClE,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,IAAI,GAAG,cAAc,CAAA;AAEzD,wBAAgB,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAA;AACjD,wBAAgB,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,CAAA;AAC/D,wBAAgB,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;AACzE,wBAAgB,IAAI,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAA;AAgBvF,eAAO,MAAM,SAAS,EAAE,UAAU,CA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AA;AAED,eAAO,MAAM,OAAO,GAAI,SAAS,WAAW,EAAE,OAAO,WAAW,KAAG,OAElE,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,WAAW,EAAE,UAAU,UAAU,EAAE,QAAQ,MAAM,EAAE,SAAS,qBAAqB,KAAG,MAGnH,CAAA"}
@@ -12,6 +12,7 @@ import { from as fromDuration } from "@bessemer/cornerstone/temporal/duration";
12
12
  import { _isInstant, instantToLiteral } from "@bessemer/cornerstone/temporal/chrono";
13
13
  import { isString } from "@bessemer/cornerstone/string";
14
14
  import { isNil } from "@bessemer/cornerstone/object";
15
+ import { format as formatPlainDateTime, fromInstant } from "@bessemer/cornerstone/temporal/plain-date-time";
15
16
  var Namespace = namespace("instant");
16
17
  function from(value) {
17
18
  if (isNil(value)) {
@@ -82,6 +83,10 @@ var isBefore = (element, other) => {
82
83
  var isAfter = (element, other) => {
83
84
  return CompareBy(from(element), from(other)) > 0;
84
85
  };
86
+ var format = (element, timeZone, locale, options) => {
87
+ const plainDateTime = fromInstant(from(element), timeZone);
88
+ return formatPlainDateTime(plainDateTime, locale, options);
89
+ };
85
90
  export {
86
91
  CompareBy,
87
92
  EqualBy,
@@ -89,6 +94,7 @@ export {
89
94
  SchemaInstance,
90
95
  SchemaLiteral,
91
96
  add,
97
+ format,
92
98
  from,
93
99
  fromString,
94
100
  isAfter,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/temporal/instant.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, mapResult, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { _isInstant, instantToLiteral, TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\n\nexport type Instant = Temporal.Instant\nexport const Namespace = namespace('instant')\nexport type InstantLiteral = NominalType<string, typeof Namespace>\nexport type InstantLike = Instant | Date | InstantLiteral\n\nexport function from(value: InstantLike): Instant\nexport function from(value: InstantLike | null): Instant | null\nexport function from(value: InstantLike | undefined): Instant | undefined\nexport function from(value: InstantLike | null | undefined): Instant | null | undefined\nexport function from(value: InstantLike | null | undefined): Instant | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.Instant) {\n return value\n }\n if (isString(value)) {\n return fromString(value)\n }\n\n return Temporal.Instant.fromEpochMilliseconds(value.getTime())\n}\n\nexport const CompareBy: Comparator<Instant> = (first: Instant, second: Instant): number => Temporal.Instant.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<Instant, ErrorEvent> => {\n try {\n return success(Temporal.Instant.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromString = (value: string): Instant => {\n return unpackResult(parseString(value))\n}\n\nexport function toLiteral(value: InstantLike): InstantLiteral\nexport function toLiteral(value: InstantLike | null): InstantLiteral | null\nexport function toLiteral(value: InstantLike | undefined): InstantLiteral | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return instantToLiteral(from(value))\n}\n\nexport function toDate(value: InstantLike): Date\nexport function toDate(value: InstantLike | null): Date | null\nexport function toDate(value: InstantLike | undefined): Date | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return new Date(from(value).epochMilliseconds)\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => mapResult(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isInstant = _isInstant\n\nexport const now = (clock = DefaultClock): Instant => {\n return clock.instant()\n}\n\nexport const add = (element: InstantLike, duration: DurationLike): Instant => {\n return from(element).add(fromDuration(duration))\n}\n\nexport const subtract = (element: InstantLike, duration: DurationLike): Instant => {\n return from(element).subtract(fromDuration(duration))\n}\n\nexport const until = (element: InstantLike, other: InstantLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: InstantLike, unit: TimeUnit): Instant => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: InstantLike, other: InstantLike): boolean\nexport function isEqual(element: InstantLike | null, other: InstantLike | null): boolean\nexport function isEqual(element: InstantLike | undefined, other: InstantLike | undefined): boolean\nexport function isEqual(element: InstantLike | null | undefined, other: InstantLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: InstantLike, other: InstantLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: InstantLike, other: InstantLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAG1B,SAAS,sBAAsB;AAC/B,SAAS,SAAS,WAAmB,eAAe;AACpD,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,SAAS,WAAW,oBAAoB;AACxC,SAAiC,QAAQ,oBAAoB;AAC7D,SAAS,YAAY,wBAAkC;AACvD,SAAS,gBAAgB;A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QAAQ,iBAA0B;AACpD,SAAO,MAAM,QAAQ;AACvB;AAEO,IAAM,MAAM,CAAC,SAAsB,aAAoC;AAC5E,SAAO,KAAK,OAAO,EAAE,IAAI,aAAa,QAAQ,CAAC;AACjD;AAEO,IAAM,WAAW,CAAC,SAAsB,aAAoC;AACjF,SAAO,KAAK,OAAO,EAAE,SAAS,aAAa,QAAQ,CAAC;AACtD;AAEO,IAAM,QAAQ,CAAC,SAAsB,UAAiC;AAC3E,SAAO,KAAK,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;AACxC;AAEO,IAAM,QAAQ,CAAC,SAAsB,SAA4B;AACtE,SAAO,KAAK,OAAO,EAAE,MAAM,EAAE,cAAc,KAAK,CAAC;AACnD;AAKO,SAAS,QAAQ,SAAyC,OAAgD;AAC/G,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,GAAG;AAClC,WAAO,YAAY;AAAA,EACrB;AAEA,SAAO,QAAQ,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC;AAC3C;AAEO,IAAM,WAAW,CAAC,SAAsB,UAAgC;AAC7E,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,UAAU,CAAC,SAAsB,UAAgC;AAC5E,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;","names":["it"]}
1
+ {"version":3,"sources":["../../src/temporal/instant.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, mapResult, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { _isInstant, instantToLiteral, TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\nimport { DateTimeFormatOptions, format as formatPlainDateTime, fromInstant } from '@bessemer/cornerstone/temporal/plain-date-time'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\n\nexport type Instant = Temporal.Instant\nexport const Namespace = namespace('instant')\nexport type InstantLiteral = NominalType<string, typeof Namespace>\nexport type InstantLike = Instant | Date | InstantLiteral\n\nexport function from(value: InstantLike): Instant\nexport function from(value: InstantLike | null): Instant | null\nexport function from(value: InstantLike | undefined): Instant | undefined\nexport function from(value: InstantLike | null | undefined): Instant | null | undefined\nexport function from(value: InstantLike | null | undefined): Instant | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.Instant) {\n return value\n }\n if (isString(value)) {\n return fromString(value)\n }\n\n return Temporal.Instant.fromEpochMilliseconds(value.getTime())\n}\n\nexport const CompareBy: Comparator<Instant> = (first: Instant, second: Instant): number => Temporal.Instant.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<Instant, ErrorEvent> => {\n try {\n return success(Temporal.Instant.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromString = (value: string): Instant => {\n return unpackResult(parseString(value))\n}\n\nexport function toLiteral(value: InstantLike): InstantLiteral\nexport function toLiteral(value: InstantLike | null): InstantLiteral | null\nexport function toLiteral(value: InstantLike | undefined): InstantLiteral | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined\nexport function toLiteral(value: InstantLike | null | undefined): InstantLiteral | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return instantToLiteral(from(value))\n}\n\nexport function toDate(value: InstantLike): Date\nexport function toDate(value: InstantLike | null): Date | null\nexport function toDate(value: InstantLike | undefined): Date | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined\nexport function toDate(value: InstantLike | null | undefined): Date | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n return new Date(from(value).epochMilliseconds)\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => mapResult(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isInstant = _isInstant\n\nexport const now = (clock = DefaultClock): Instant => {\n return clock.instant()\n}\n\nexport const add = (element: InstantLike, duration: DurationLike): Instant => {\n return from(element).add(fromDuration(duration))\n}\n\nexport const subtract = (element: InstantLike, duration: DurationLike): Instant => {\n return from(element).subtract(fromDuration(duration))\n}\n\nexport const until = (element: InstantLike, other: InstantLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: InstantLike, unit: TimeUnit): Instant => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: InstantLike, other: InstantLike): boolean\nexport function isEqual(element: InstantLike | null, other: InstantLike | null): boolean\nexport function isEqual(element: InstantLike | undefined, other: InstantLike | undefined): boolean\nexport function isEqual(element: InstantLike | null | undefined, other: InstantLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: InstantLike, other: InstantLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: InstantLike, other: InstantLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport const format = (element: InstantLike, timeZone: TimeZoneId, locale: Locale, options: DateTimeFormatOptions): string => {\n const plainDateTime = fromInstant(from(element), timeZone)\n return formatPlainDateTime(plainDateTime, locale, options)\n}\n"],"mappings":";AAAA,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,YAAY,KAAK,OAAO,GAAG,QAAQ;AACzD,SAAO,oBAAoB,eAAe,QAAQ,OAAO;AAC3D;","names":["it"]}
@@ -0,0 +1,61 @@
1
+ import { Temporal } from '@js-temporal/polyfill';
2
+ import { NominalType } from '@bessemer/cornerstone/types';
3
+ import { Comparator } from '@bessemer/cornerstone/comparator';
4
+ import { Result } from '@bessemer/cornerstone/result';
5
+ import { ErrorEvent } from '@bessemer/cornerstone/error/error-event';
6
+ import Zod from 'zod';
7
+ import { Duration, DurationLike } from '@bessemer/cornerstone/temporal/duration';
8
+ import { InstantLike } from '@bessemer/cornerstone/temporal/instant';
9
+ import { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id';
10
+ import { TimeUnit } from '@bessemer/cornerstone/temporal/chrono';
11
+ import { PlainTimeBuilder, TimeFormatOptions } from '@bessemer/cornerstone/temporal/plain-time';
12
+ import { Locale } from '@bessemer/cornerstone/intl/locale';
13
+ export type PlainDateTime = Temporal.PlainDateTime;
14
+ export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"plain-date-time">;
15
+ export type PlainDateTimeLiteral = NominalType<string, typeof Namespace>;
16
+ export type PlainDateTimeBuilder = PlainTimeBuilder & {
17
+ year?: number;
18
+ month?: number;
19
+ day?: number;
20
+ };
21
+ export type PlainDateTimeLike = PlainDateTime | PlainDateTimeLiteral | PlainDateTimeBuilder;
22
+ export declare function from(value: PlainDateTimeLike): PlainDateTime;
23
+ export declare function from(value: PlainDateTimeLike | null): PlainDateTime | null;
24
+ export declare function from(value: PlainDateTimeLike | undefined): PlainDateTime | undefined;
25
+ export declare function from(value: PlainDateTimeLike | null | undefined): PlainDateTime | null | undefined;
26
+ export declare const CompareBy: Comparator<PlainDateTime>;
27
+ export declare const EqualBy: import("@bessemer/cornerstone/equalitor").Equalitor<Temporal.PlainDateTime>;
28
+ export declare const parseString: (value: string) => Result<PlainDateTime, ErrorEvent>;
29
+ export declare const fromString: (value: string) => PlainDateTime;
30
+ export declare const fromInstant: (instant: InstantLike, zone: TimeZoneId) => PlainDateTime;
31
+ export declare function toLiteral(likeValue: PlainDateTimeLike): PlainDateTimeLiteral;
32
+ export declare function toLiteral(likeValue: PlainDateTimeLike | null): PlainDateTimeLiteral | null;
33
+ export declare function toLiteral(likeValue: PlainDateTimeLike | undefined): PlainDateTimeLiteral | undefined;
34
+ export declare function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined;
35
+ export declare const SchemaLiteral: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<PlainDateTimeLiteral, string>>;
36
+ export declare const SchemaInstance: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<Temporal.PlainDateTime, string>>;
37
+ export declare const isPlainDateTime: (value: unknown) => value is PlainDateTime;
38
+ export declare const now: (clock?: {
39
+ readonly zone: TimeZoneId;
40
+ instant(): import("@bessemer/cornerstone/temporal/instant").Instant;
41
+ withZone(zone: TimeZoneId): import("@bessemer/cornerstone/temporal/clock").Clock;
42
+ }) => PlainDateTime;
43
+ export declare const merge: (element: PlainDateTimeLike, builder: PlainDateTimeBuilder) => PlainDateTime;
44
+ export declare const add: (element: PlainDateTimeLike, duration: DurationLike) => PlainDateTime;
45
+ export declare const subtract: (element: PlainDateTimeLike, duration: DurationLike) => PlainDateTime;
46
+ export declare const until: (element: PlainDateTimeLike, other: PlainDateTimeLike) => Duration;
47
+ export declare const round: (element: PlainDateTimeLike, unit: TimeUnit) => PlainDateTime;
48
+ export declare function isEqual(element: PlainDateTimeLike, other: PlainDateTimeLike): boolean;
49
+ export declare function isEqual(element: PlainDateTimeLike | null, other: PlainDateTimeLike | null): boolean;
50
+ export declare function isEqual(element: PlainDateTimeLike | undefined, other: PlainDateTimeLike | undefined): boolean;
51
+ export declare const isBefore: (element: PlainDateTimeLike, other: PlainDateTimeLike) => boolean;
52
+ export declare const isAfter: (element: PlainDateTimeLike, other: PlainDateTimeLike) => boolean;
53
+ export type DateTimeFormatOptions = TimeFormatOptions & {
54
+ era?: 'long' | 'short' | 'narrow' | undefined;
55
+ weekday?: 'long' | 'short' | 'narrow' | undefined;
56
+ year?: 'numeric' | '2-digit' | undefined;
57
+ month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow' | undefined;
58
+ day?: 'numeric' | '2-digit' | undefined;
59
+ };
60
+ export declare const format: (element: PlainDateTimeLike, locale: Locale, options: DateTimeFormatOptions) => string;
61
+ //# sourceMappingURL=plain-date-time.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plain-date-time.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-date-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAsB,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAyB,MAAM,yCAAyC,CAAA;AACvG,OAAO,EAAwB,WAAW,EAAE,MAAM,wCAAwC,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAA;AAGhE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAA;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE1D,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAA;AAClD,eAAO,MAAM,SAAS,mFAA+B,CAAA;AACrD,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AACxE,MAAM,MAAM,oBAAoB,G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,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC7C,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACjD,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;IACxC,KAAK,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACvE,GAAG,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;CACxC,CAAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,iBAAiB,EAAE,QAAQ,MAAM,EAAE,SAAS,qBAAqB,KAAG,MAgBnG,CAAA"}
@@ -0,0 +1,126 @@
1
+ // src/temporal/plain-date-time.ts
2
+ import { Temporal } from "@js-temporal/polyfill";
3
+ import { namespace } from "@bessemer/cornerstone/resource-key";
4
+ import { fromComparator } from "@bessemer/cornerstone/equalitor";
5
+ import { failure, mapResult, success } from "@bessemer/cornerstone/result";
6
+ import { invalidValue, unpackResult } from "@bessemer/cornerstone/error/error-event";
7
+ import { isError } from "@bessemer/cornerstone/error/error";
8
+ import { structuredTransform } from "@bessemer/cornerstone/zod-util";
9
+ import Zod from "zod";
10
+ import { Default as DefaultClock } from "@bessemer/cornerstone/temporal/clock";
11
+ import { from as _fromDuration } from "@bessemer/cornerstone/temporal/duration";
12
+ import { from as _fromInstant } from "@bessemer/cornerstone/temporal/instant";
13
+ import { isString } from "@bessemer/cornerstone/string";
14
+ import { isNil } from "@bessemer/cornerstone/object";
15
+ var Namespace = namespace("plain-date-time");
16
+ function from(value) {
17
+ if (isNil(value)) {
18
+ return value;
19
+ }
20
+ if (value instanceof Temporal.PlainDateTime) {
21
+ return value;
22
+ }
23
+ if (isString(value)) {
24
+ return fromString(value);
25
+ }
26
+ return Temporal.PlainDateTime.from(value);
27
+ }
28
+ var CompareBy = (first, second) => Temporal.PlainDateTime.compare(first, second);
29
+ var EqualBy = fromComparator(CompareBy);
30
+ var parseString = (value) => {
31
+ try {
32
+ return success(Temporal.PlainDateTime.from(value));
33
+ } catch (e) {
34
+ if (!isError(e)) {
35
+ throw e;
36
+ }
37
+ return failure(invalidValue(value, { namespace: Namespace, message: e.message }));
38
+ }
39
+ };
40
+ var fromString = (value) => {
41
+ return unpackResult(parseString(value));
42
+ };
43
+ var fromInstant = (instant, zone) => {
44
+ return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainDateTime();
45
+ };
46
+ function toLiteral(likeValue) {
47
+ if (isNil(likeValue)) {
48
+ return likeValue;
49
+ }
50
+ const value = from(likeValue);
51
+ return value.toString();
52
+ }
53
+ var SchemaLiteral = structuredTransform(Zod.string(), (it) => mapResult(parseString(it), (it2) => toLiteral(it2)));
54
+ var SchemaInstance = structuredTransform(Zod.string(), parseString);
55
+ var isPlainDateTime = (value) => {
56
+ return value instanceof Temporal.PlainDateTime;
57
+ };
58
+ var now = (clock = DefaultClock) => {
59
+ return fromInstant(clock.instant(), clock.zone);
60
+ };
61
+ var merge = (element, builder) => {
62
+ return from(element).with(builder);
63
+ };
64
+ var add = (element, duration) => {
65
+ return from(element).add(_fromDuration(duration));
66
+ };
67
+ var subtract = (element, duration) => {
68
+ return from(element).subtract(_fromDuration(duration));
69
+ };
70
+ var until = (element, other) => {
71
+ return from(element).until(from(other));
72
+ };
73
+ var round = (element, unit) => {
74
+ return from(element).round({ smallestUnit: unit });
75
+ };
76
+ function isEqual(element, other) {
77
+ if (isNil(element) || isNil(other)) {
78
+ return element === other;
79
+ }
80
+ return EqualBy(from(element), from(other));
81
+ }
82
+ var isBefore = (element, other) => {
83
+ return CompareBy(from(element), from(other)) < 0;
84
+ };
85
+ var isAfter = (element, other) => {
86
+ return CompareBy(from(element), from(other)) > 0;
87
+ };
88
+ var format = (element, locale, options) => {
89
+ const plainDateTime = from(element);
90
+ const date = new Date(
91
+ plainDateTime.year,
92
+ plainDateTime.month - 1,
93
+ // Date months are 0-based
94
+ plainDateTime.day,
95
+ plainDateTime.hour,
96
+ plainDateTime.minute,
97
+ plainDateTime.second,
98
+ plainDateTime.millisecond
99
+ );
100
+ const formatter = new Intl.DateTimeFormat(locale, options);
101
+ return formatter.format(date);
102
+ };
103
+ export {
104
+ CompareBy,
105
+ EqualBy,
106
+ Namespace,
107
+ SchemaInstance,
108
+ SchemaLiteral,
109
+ add,
110
+ format,
111
+ from,
112
+ fromInstant,
113
+ fromString,
114
+ isAfter,
115
+ isBefore,
116
+ isEqual,
117
+ isPlainDateTime,
118
+ merge,
119
+ now,
120
+ parseString,
121
+ round,
122
+ subtract,
123
+ toLiteral,
124
+ until
125
+ };
126
+ //# sourceMappingURL=plain-date-time.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/temporal/plain-date-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, mapResult, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { PlainTimeBuilder, TimeFormatOptions } from '@bessemer/cornerstone/temporal/plain-time'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\n\nexport type PlainDateTime = Temporal.PlainDateTime\nexport const Namespace = namespace('plain-date-time')\nexport type PlainDateTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainDateTimeBuilder = PlainTimeBuilder & {\n year?: number\n month?: number\n day?: number\n}\n\nexport type PlainDateTimeLike = PlainDateTime | PlainDateTimeLiteral | PlainDateTimeBuilder\n\nexport function from(value: PlainDateTimeLike): PlainDateTime\nexport function from(value: PlainDateTimeLike | null): PlainDateTime | null\nexport function from(value: PlainDateTimeLike | undefined): PlainDateTime | undefined\nexport function from(value: PlainDateTimeLike | null | undefined): PlainDateTime | null | undefined\nexport function from(value: PlainDateTimeLike | null | undefined): PlainDateTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainDateTime) {\n return value\n }\n\n if (isString(value)) {\n return fromString(value)\n }\n\n return Temporal.PlainDateTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainDateTime> = (first: PlainDateTime, second: PlainDateTime): number =>\n Temporal.PlainDateTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainDateTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainDateTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromString = (value: string): PlainDateTime => {\n return unpackResult(parseString(value))\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainDateTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainDateTime()\n}\n\nexport function toLiteral(likeValue: PlainDateTimeLike): PlainDateTimeLiteral\nexport function toLiteral(likeValue: PlainDateTimeLike | null): PlainDateTimeLiteral | null\nexport function toLiteral(likeValue: PlainDateTimeLike | undefined): PlainDateTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainDateTimeLike | null | undefined): PlainDateTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n return value.toString() as PlainDateTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => mapResult(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isPlainDateTime = (value: unknown): value is PlainDateTime => {\n return value instanceof Temporal.PlainDateTime\n}\n\nexport const now = (clock = DefaultClock): PlainDateTime => {\n return fromInstant(clock.instant(), clock.zone)\n}\n\nexport const merge = (element: PlainDateTimeLike, builder: PlainDateTimeBuilder): PlainDateTime => {\n return from(element).with(builder)\n}\n\nexport const add = (element: PlainDateTimeLike, duration: DurationLike): PlainDateTime => {\n return from(element).add(_fromDuration(duration))\n}\n\nexport const subtract = (element: PlainDateTimeLike, duration: DurationLike): PlainDateTime => {\n return from(element).subtract(_fromDuration(duration))\n}\n\nexport const until = (element: PlainDateTimeLike, other: PlainDateTimeLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: PlainDateTimeLike, unit: TimeUnit): PlainDateTime => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: PlainDateTimeLike, other: PlainDateTimeLike): boolean\nexport function isEqual(element: PlainDateTimeLike | null, other: PlainDateTimeLike | null): boolean\nexport function isEqual(element: PlainDateTimeLike | undefined, other: PlainDateTimeLike | undefined): boolean\nexport function isEqual(element: PlainDateTimeLike | null | undefined, other: PlainDateTimeLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: PlainDateTimeLike, other: PlainDateTimeLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: PlainDateTimeLike, other: PlainDateTimeLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport type DateTimeFormatOptions = TimeFormatOptions & {\n era?: 'long' | 'short' | 'narrow' | undefined\n weekday?: 'long' | 'short' | 'narrow' | undefined\n year?: 'numeric' | '2-digit' | undefined\n month?: 'numeric' | '2-digit' | 'long' | 'short' | 'narrow' | undefined\n day?: 'numeric' | '2-digit' | undefined\n}\n\nexport const format = (element: PlainDateTimeLike, locale: Locale, options: DateTimeFormatOptions): string => {\n const plainDateTime = from(element)\n\n // Convert PlainDateTime to Date\n const date = new Date(\n plainDateTime.year,\n plainDateTime.month - 1, // Date months are 0-based\n plainDateTime.day,\n plainDateTime.hour,\n plainDateTime.minute,\n plainDateTime.second,\n plainDateTime.millisecond\n )\n\n const formatter = new Intl.DateTimeFormat(locale, options)\n return formatter.format(date)\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAG1B,SAAS,sBAAsB;AAC/B,SAAS,SAAS,WAAmB,eAAe;AACpD,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,SAAS,WAAW,oBAAoB;AACxC,SAAiC,QAAQ,qBAAqB;AAC9D,SAAS,QAAQ,oBAAiC;AAGlD,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAKf,IAAM,YAAY,UAAU,iBAAiB;AAc7C,SAAS,KAAK,OAA+E;AAClG,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,SAAS,eAAe;AAC3C,WAAO;AAAA,EACT;AAEA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,WAAW,KAAK;AAAA,EACzB;AAEA,SAAO,SAAS,cAAc,KAAK,KAAK;AAC1C;AAEO,IAAM,YAAuC,CAAC,OAAsB,WACzE,SAAS,cAAc,QAAQ,OAAO,MAAM;AACvC,IAAM,UAAU,eAAe,SAAS;AAExC,IAAM,cAAc,CAAC,UAAqD;AAC/E,MAAI;AACF,WAAO,QAAQ,SAAS,cAAc,KAAK,KAAK,CAAC;AAAA,EACnD,SAAS,GAAG;AACV,QAAI,CAAC,QAAQ,CA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AAO,EAAE,MAAM,EAAE,cAAc,KAAK,CAAC;AACnD;AAKO,SAAS,QAAQ,SAA+C,OAAsD;AAC3H,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,GAAG;AAClC,WAAO,YAAY;AAAA,EACrB;AAEA,SAAO,QAAQ,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC;AAC3C;AAEO,IAAM,WAAW,CAAC,SAA4B,UAAsC;AACzF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,UAAU,CAAC,SAA4B,UAAsC;AACxF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAUO,IAAM,SAAS,CAAC,SAA4B,QAAgB,YAA2C;AAC5G,QAAM,gBAAgB,KAAK,OAAO;AAGlC,QAAM,OAAO,IAAI;AAAA,IACf,cAAc;AAAA,IACd,cAAc,QAAQ;AAAA;AAAA,IACtB,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,IACd,cAAc;AAAA,EAChB;AAEA,QAAM,YAAY,IAAI,KAAK,eAAe,QAAQ,OAAO;AACzD,SAAO,UAAU,OAAO,IAAI;AAC9B;","names":["it"]}
@@ -8,6 +8,7 @@ import { Duration, DurationLike } from '@bessemer/cornerstone/temporal/duration'
8
8
  import { InstantLike } from '@bessemer/cornerstone/temporal/instant';
9
9
  import { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id';
10
10
  import { TimeUnit } from '@bessemer/cornerstone/temporal/chrono';
11
+ import { Locale } from '@bessemer/cornerstone/intl/locale';
11
12
  export type PlainTime = Temporal.PlainTime;
12
13
  export declare const Namespace: import("@bessemer/cornerstone/resource-key").ResourceNamespace<"plain-time">;
13
14
  export type PlainTimeLiteral = NominalType<string, typeof Namespace>;
@@ -52,6 +53,13 @@ export declare function isEqual(element: PlainTimeLike | null, other: PlainTimeL
52
53
  export declare function isEqual(element: PlainTimeLike | undefined, other: PlainTimeLike | undefined): boolean;
53
54
  export declare const isBefore: (element: PlainTimeLike, other: PlainTimeLike) => boolean;
54
55
  export declare const isAfter: (element: PlainTimeLike, other: PlainTimeLike) => boolean;
56
+ export type TimeFormatOptions = {
57
+ hour12?: boolean | undefined;
58
+ hour?: 'numeric' | '2-digit' | undefined;
59
+ minute?: 'numeric' | '2-digit' | undefined;
60
+ second?: 'numeric' | '2-digit' | undefined;
61
+ };
62
+ export declare const format: (element: PlainTimeLike, locale: Locale, options?: TimeFormatOptions) => string;
55
63
  export declare const Midnight: Temporal.PlainTime;
56
64
  export declare const Noon: Temporal.PlainTime;
57
65
  //# sourceMappingURL=plain-time.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plain-time.d.ts","sourceRoot":"","sources":["../../src/temporal/plain-time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAA;AAE7D,OAAO,EAAsB,MAAM,EAAW,MAAM,8BAA8B,CAAA;AAClF,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAGhG,OAAO,GAAG,MAAM,KAAK,CAAA;AAErB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAyB,MAAM,yCAAyC,CAAA;AACvG,OAAO,EAAwB,WAAW,EAAE,MAAM,wCAAwC,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAA;AAIhE,MAAM,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAA;AAC1C,eAAO,MAAM,SAAS,8EAA0B,CAAA;AAChD,MAAM,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AACpE,MAAM,MAAM,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AAA;AAED,eAAO,MAAM,MAAM,GAAI,SAAS,aAAa,EAAE,QAAQ,MAAM,EAAE,UAAU,iBAAiB,KAAG,MAY5F,CAAA;AAED,eAAO,MAAM,QAAQ,oBAA0B,CAAA;AAC/C,eAAO,MAAM,IAAI,oBAAqB,CAAA"}
@@ -91,6 +91,15 @@ var isBefore = (element, other) => {
91
91
  var isAfter = (element, other) => {
92
92
  return CompareBy(from(element), from(other)) > 0;
93
93
  };
94
+ var format = (element, locale, options) => {
95
+ const plainTime = from(element);
96
+ const date = new Date(1970, 0, 1, plainTime.hour, plainTime.minute, plainTime.second, plainTime.millisecond);
97
+ if (isNil(options) || isNil(options.hour) && isNil(options.minute) && isNil(options.second)) {
98
+ options = { ...options, hour: "numeric", minute: "2-digit", ...plainTime.second > 0 || plainTime.millisecond > 0 ? { second: "2-digit" } : {} };
99
+ }
100
+ const formatter = new Intl.DateTimeFormat(locale, options);
101
+ return formatter.format(date);
102
+ };
94
103
  var Midnight = from({ nanosecond: 0 });
95
104
  var Noon = from({ hour: 12 });
96
105
  export {
@@ -102,6 +111,7 @@ export {
102
111
  SchemaInstance,
103
112
  SchemaLiteral,
104
113
  add,
114
+ format,
105
115
  from,
106
116
  fromDuration,
107
117
  fromInstant,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/temporal/plain-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, mapResult, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\n\nexport type PlainTime = Temporal.PlainTime\nexport const Namespace = namespace('plain-time')\nexport type PlainTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainTimeBuilder = {\n hour?: number\n minute?: number\n second?: number\n millisecond?: number\n microsecond?: number\n nanosecond?: number\n}\nexport type PlainTimeLike = PlainTime | PlainTimeLiteral | PlainTimeBuilder\n\nexport function from(value: PlainTimeLike): PlainTime\nexport function from(value: PlainTimeLike | null): PlainTime | null\nexport function from(value: PlainTimeLike | undefined): PlainTime | undefined\nexport function from(value: PlainTimeLike | null | undefined): PlainTime | null | undefined\nexport function from(value: PlainTimeLike | null | undefined): PlainTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainTime) {\n return value\n }\n if (isString(value)) {\n return fromString(value)\n }\n\n return Temporal.PlainTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainTime> = (first: PlainTime, second: PlainTime): number => Temporal.PlainTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromString = (value: string): PlainTime => {\n return unpackResult(parseString(value))\n}\n\nexport const fromDuration = (duration: DurationLike): PlainTime => {\n return Midnight.add(_fromDuration(duration))\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainTime()\n}\n\nexport function toLiteral(likeValue: PlainTimeLike): PlainTimeLiteral\nexport function toLiteral(likeValue: PlainTimeLike | null): PlainTimeLiteral | null\nexport function toLiteral(likeValue: PlainTimeLike | undefined): PlainTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n\n if (value.second === 0 && value.millisecond === 0 && value.microsecond === 0 && value.nanosecond === 0) {\n return `${value.hour.toString().padStart(2, '0')}:${value.minute.toString().padStart(2, '0')}` as PlainTimeLiteral\n }\n\n return value.toString() as PlainTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => mapResult(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isPlainTime = (value: unknown): value is PlainTime => {\n return value instanceof Temporal.PlainTime\n}\n\nexport const now = (clock = DefaultClock): PlainTime => {\n return fromInstant(clock.instant(), clock.zone)\n}\n\nexport const merge = (element: PlainTimeLike, builder: PlainTimeBuilder): PlainTime => {\n return from(element).with(builder)\n}\n\nexport const add = (element: PlainTimeLike, duration: DurationLike): PlainTime => {\n return from(element).add(_fromDuration(duration))\n}\n\nexport const subtract = (element: PlainTimeLike, duration: DurationLike): PlainTime => {\n return from(element).subtract(_fromDuration(duration))\n}\n\nexport const until = (element: PlainTimeLike, other: PlainTimeLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: PlainTimeLike, unit: TimeUnit): PlainTime => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: PlainTimeLike, other: PlainTimeLike): boolean\nexport function isEqual(element: PlainTimeLike | null, other: PlainTimeLike | null): boolean\nexport function isEqual(element: PlainTimeLike | undefined, other: PlainTimeLike | undefined): boolean\nexport function isEqual(element: PlainTimeLike | null | undefined, other: PlainTimeLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: PlainTimeLike, other: PlainTimeLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: PlainTimeLike, other: PlainTimeLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport const Midnight = from({ nanosecond: 0 })\nexport const Noon = from({ hour: 12 })\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAG1B,SAAS,sBAAsB;AAC/B,SAAS,SAAS,WAAmB,eAAe;AACpD,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,SAAS,WAAW,oBAAoB;AACxC,SAAiC,QAAQ,qBAAqB;AAC9D,SAAS,QAAQ,oBAAiC;AAGlD,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAGf,IAAM,YAAY,UAAU,YAAY;AAgBxC,SAAS,KAAK,OAAuE;AAC1F,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,SAAS,WAAW;AACvC,WAAO;AAAA,EACT;AACA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,WAAW,KAAK;AAAA,EACzB;AAEA,SAAO,SAAS,UAAU,KAAK,KAAK;AACtC;AAEO,IAAM,YAAmC,CAAC,OAAkB,WAA8B,SAAS,UAAU,QAAQ,OAAO,MAAM;AAClI,IAAM,UAAU,eAAe,SAAS;AAExC,IAAM,cAAc,CAAC,UAAiD;AAC3E,MAAI;AACF,WAAO,QAAQ,SAAS,UAAU,KAAK,KAAK,CAAC;AAAA,EAC/C,SAAS,GAAG;AACV,QAAI,CAAC,QAAQ,CAAC,GAAG;AACf,YAAM;AAAA,IACR;AAEA,WAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,EAAE,QAAQ,CAAC,CAAC;AAAA,EAClF;AACF;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AC;AACvD;AAEO,IAAM,QAAQ,CAAC,SAAwB,UAAmC;AAC/E,SAAO,KAAK,OAAO,EAAE,MAAM,KAAK,KAAK,CAAC;AACxC;AAEO,IAAM,QAAQ,CAAC,SAAwB,SAA8B;AAC1E,SAAO,KAAK,OAAO,EAAE,MAAM,EAAE,cAAc,KAAK,CAAC;AACnD;AAKO,SAAS,QAAQ,SAA2C,OAAkD;AACnH,MAAI,MAAM,OAAO,KAAK,MAAM,KAAK,GAAG;AAClC,WAAO,YAAY;AAAA,EACrB;AAEA,SAAO,QAAQ,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC;AAC3C;AAEO,IAAM,WAAW,CAAC,SAAwB,UAAkC;AACjF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,UAAU,CAAC,SAAwB,UAAkC;AAChF,SAAO,UAAU,KAAK,OAAO,GAAG,KAAK,KAAK,CAAC,IAAI;AACjD;AAEO,IAAM,WAAW,KAAK,EAAE,YAAY,EAAE,CAAC;AACvC,IAAM,OAAO,KAAK,EAAE,MAAM,GAAG,CAAC;","names":["it"]}
1
+ {"version":3,"sources":["../../src/temporal/plain-time.ts"],"sourcesContent":["import { Temporal } from '@js-temporal/polyfill'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { Comparator } from '@bessemer/cornerstone/comparator'\nimport { fromComparator } from '@bessemer/cornerstone/equalitor'\nimport { failure, mapResult, Result, success } from '@bessemer/cornerstone/result'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\nimport Zod from 'zod'\nimport { Default as DefaultClock } from '@bessemer/cornerstone/temporal/clock'\nimport { Duration, DurationLike, from as _fromDuration } from '@bessemer/cornerstone/temporal/duration'\nimport { from as _fromInstant, InstantLike } from '@bessemer/cornerstone/temporal/instant'\nimport { TimeZoneId } from '@bessemer/cornerstone/temporal/time-zone-id'\nimport { TimeUnit } from '@bessemer/cornerstone/temporal/chrono'\nimport { isString } from '@bessemer/cornerstone/string'\nimport { isNil } from '@bessemer/cornerstone/object'\nimport { Locale } from '@bessemer/cornerstone/intl/locale'\n\nexport type PlainTime = Temporal.PlainTime\nexport const Namespace = namespace('plain-time')\nexport type PlainTimeLiteral = NominalType<string, typeof Namespace>\nexport type PlainTimeBuilder = {\n hour?: number\n minute?: number\n second?: number\n millisecond?: number\n microsecond?: number\n nanosecond?: number\n}\nexport type PlainTimeLike = PlainTime | PlainTimeLiteral | PlainTimeBuilder\n\nexport function from(value: PlainTimeLike): PlainTime\nexport function from(value: PlainTimeLike | null): PlainTime | null\nexport function from(value: PlainTimeLike | undefined): PlainTime | undefined\nexport function from(value: PlainTimeLike | null | undefined): PlainTime | null | undefined\nexport function from(value: PlainTimeLike | null | undefined): PlainTime | null | undefined {\n if (isNil(value)) {\n return value\n }\n\n if (value instanceof Temporal.PlainTime) {\n return value\n }\n if (isString(value)) {\n return fromString(value)\n }\n\n return Temporal.PlainTime.from(value)\n}\n\nexport const CompareBy: Comparator<PlainTime> = (first: PlainTime, second: PlainTime): number => Temporal.PlainTime.compare(first, second)\nexport const EqualBy = fromComparator(CompareBy)\n\nexport const parseString = (value: string): Result<PlainTime, ErrorEvent> => {\n try {\n return success(Temporal.PlainTime.from(value))\n } catch (e) {\n if (!isError(e)) {\n throw e\n }\n\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n }\n}\n\nexport const fromString = (value: string): PlainTime => {\n return unpackResult(parseString(value))\n}\n\nexport const fromDuration = (duration: DurationLike): PlainTime => {\n return Midnight.add(_fromDuration(duration))\n}\n\nexport const fromInstant = (instant: InstantLike, zone: TimeZoneId): PlainTime => {\n return _fromInstant(instant).toZonedDateTimeISO(zone).toPlainTime()\n}\n\nexport function toLiteral(likeValue: PlainTimeLike): PlainTimeLiteral\nexport function toLiteral(likeValue: PlainTimeLike | null): PlainTimeLiteral | null\nexport function toLiteral(likeValue: PlainTimeLike | undefined): PlainTimeLiteral | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined\nexport function toLiteral(likeValue: PlainTimeLike | null | undefined): PlainTimeLiteral | null | undefined {\n if (isNil(likeValue)) {\n return likeValue\n }\n\n const value = from(likeValue)\n\n if (value.second === 0 && value.millisecond === 0 && value.microsecond === 0 && value.nanosecond === 0) {\n return `${value.hour.toString().padStart(2, '0')}:${value.minute.toString().padStart(2, '0')}` as PlainTimeLiteral\n }\n\n return value.toString() as PlainTimeLiteral\n}\n\nexport const SchemaLiteral = structuredTransform(Zod.string(), (it: string) => mapResult(parseString(it), (it) => toLiteral(it)))\nexport const SchemaInstance = structuredTransform(Zod.string(), parseString)\n\nexport const isPlainTime = (value: unknown): value is PlainTime => {\n return value instanceof Temporal.PlainTime\n}\n\nexport const now = (clock = DefaultClock): PlainTime => {\n return fromInstant(clock.instant(), clock.zone)\n}\n\nexport const merge = (element: PlainTimeLike, builder: PlainTimeBuilder): PlainTime => {\n return from(element).with(builder)\n}\n\nexport const add = (element: PlainTimeLike, duration: DurationLike): PlainTime => {\n return from(element).add(_fromDuration(duration))\n}\n\nexport const subtract = (element: PlainTimeLike, duration: DurationLike): PlainTime => {\n return from(element).subtract(_fromDuration(duration))\n}\n\nexport const until = (element: PlainTimeLike, other: PlainTimeLike): Duration => {\n return from(element).until(from(other))\n}\n\nexport const round = (element: PlainTimeLike, unit: TimeUnit): PlainTime => {\n return from(element).round({ smallestUnit: unit })\n}\n\nexport function isEqual(element: PlainTimeLike, other: PlainTimeLike): boolean\nexport function isEqual(element: PlainTimeLike | null, other: PlainTimeLike | null): boolean\nexport function isEqual(element: PlainTimeLike | undefined, other: PlainTimeLike | undefined): boolean\nexport function isEqual(element: PlainTimeLike | null | undefined, other: PlainTimeLike | null | undefined): boolean {\n if (isNil(element) || isNil(other)) {\n return element === other\n }\n\n return EqualBy(from(element), from(other))\n}\n\nexport const isBefore = (element: PlainTimeLike, other: PlainTimeLike): boolean => {\n return CompareBy(from(element), from(other)) < 0\n}\n\nexport const isAfter = (element: PlainTimeLike, other: PlainTimeLike): boolean => {\n return CompareBy(from(element), from(other)) > 0\n}\n\nexport type TimeFormatOptions = {\n hour12?: boolean | undefined\n hour?: 'numeric' | '2-digit' | undefined\n minute?: 'numeric' | '2-digit' | undefined\n second?: 'numeric' | '2-digit' | undefined\n}\n\nexport const format = (element: PlainTimeLike, locale: Locale, options?: TimeFormatOptions): string => {\n const plainTime = from(element)\n\n // Create a Date at Unix epoch with the time components\n const date = new Date(1970, 0, 1, plainTime.hour, plainTime.minute, plainTime.second, plainTime.millisecond)\n\n if (isNil(options) || (isNil(options.hour) && isNil(options.minute) && isNil(options.second))) {\n options = { ...options, hour: 'numeric', minute: '2-digit', ...(plainTime.second > 0 || plainTime.millisecond > 0 ? { second: '2-digit' } : {}) }\n }\n\n const formatter = new Intl.DateTimeFormat(locale, options)\n return formatter.format(date)\n}\n\nexport const Midnight = from({ nanosecond: 0 })\nexport const Noon = from({ hour: 12 })\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAG1B,SAAS,sBAAsB;AAC/B,SAAS,SAAS,WAAmB,eAAe;AACpD,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AACpC,OAAO,SAAS;AAChB,SAAS,WAAW,oBAAoB;AACxC,SAAiC,QAAQ,qBAAqB;AAC9D,SAAS,QAAQ,oBAAiC;AAGlD,SAAS,gBAAgB;AACzB,SAAS,aAAa;AAIf,IAAM,YAAY,UAAU,YAAY;AAgBxC,SAAS,KAAK,OAAuE;AAC1F,MAAI,MAAM,KAAK,GAAG;AAChB,WAAO;AAAA,EACT;AAEA,MAAI,iBAAiB,SAAS,WAAW;AACvC,WAAO;AAAA,EACT;AACA,MAAI,SAAS,KAAK,GAAG;AACnB,WAAO,WAAW,KAAK;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AM,MAAM,QAAQ,IAAI,KAAK,MAAM,QAAQ,MAAM,KAAK,MAAM,QAAQ,MAAM,GAAI;AAC7F,cAAU,EAAE,GAAG,SAAS,MAAM,WAAW,QAAQ,WAAW,GAAI,UAAU,SAAS,KAAK,UAAU,cAAc,IAAI,EAAE,QAAQ,UAAU,IAAI,CAAC,EAAG;AAAA,EAClJ;AAEA,QAAM,YAAY,IAAI,KAAK,eAAe,QAAQ,OAAO;AACzD,SAAO,UAAU,OAAO,IAAI;AAC9B;AAEO,IAAM,WAAW,KAAK,EAAE,YAAY,EAAE,CAAC;AACvC,IAAM,OAAO,KAAK,EAAE,MAAM,GAAG,CAAC;","names":["it"]}
@@ -8,5 +8,5 @@ export declare const parseString: (value: string) => Result<TimeZoneId, ErrorEve
8
8
  export declare const fromString: (value: string) => TimeZoneId;
9
9
  export declare const Schema: Zod.ZodPipe<Zod.ZodString, Zod.ZodTransform<TimeZoneId, string>>;
10
10
  export declare const Utc: TimeZoneId;
11
- export declare const SystemDefault: TimeZoneId;
11
+ export declare const getSystemDefault: () => TimeZoneId;
12
12
  //# sourceMappingURL=time-zone-id.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time-zone-id.d.ts","sourceRoot":"","sources":["../../src/temporal/time-zone-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAIhG,eAAO,MAAM,SAAS,gFAA4B,CAAA;AAClD,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE9D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAWxE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,UAE1C,CAAA;AAED,eAAO,MAAM,MAAM,kEAAiD,CAAA;AAEpE,eAAO,MAAM,GAAG,EAAY,UAAU,CAAA;AACtC,eAAO,MAAM,aAAa,EAAuD,UAAU,CAAA"}
1
+ {"version":3,"file":"time-zone-id.d.ts","sourceRoot":"","sources":["../../src/temporal/time-zone-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAW,MAAM,8BAA8B,CAAA;AACvE,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,EAAE,UAAU,EAA8B,MAAM,yCAAyC,CAAA;AAIhG,eAAO,MAAM,SAAS,gFAA4B,CAAA;AAClD,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,SAAS,CAAC,CAAA;AAE9D,eAAO,MAAM,WAAW,GAAI,OAAO,MAAM,KAAG,MAAM,CAAC,UAAU,EAAE,UAAU,CAWxE,CAAA;AAED,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,KAAG,UAE1C,CAAA;AAED,eAAO,MAAM,MAAM,kEAAiD,CAAA;AAEpE,eAAO,MAAM,GAAG,EAAY,UAAU,CAAA;AACtC,eAAO,MAAM,gBAAgB,QAAO,UAEnC,CAAA"}
@@ -23,13 +23,15 @@ var fromString = (value) => {
23
23
  };
24
24
  var Schema = structuredTransform(Zod.string(), parseString);
25
25
  var Utc = "UTC";
26
- var SystemDefault = Intl.DateTimeFormat().resolvedOptions().timeZone;
26
+ var getSystemDefault = () => {
27
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
28
+ };
27
29
  export {
28
30
  Namespace,
29
31
  Schema,
30
- SystemDefault,
31
32
  Utc,
32
33
  fromString,
34
+ getSystemDefault,
33
35
  parseString
34
36
  };
35
37
  //# sourceMappingURL=time-zone-id.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/temporal/time-zone-id.ts"],"sourcesContent":["import { failure, Result, success } from '@bessemer/cornerstone/result'\nimport Zod from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = namespace('time-zone-id')\nexport type TimeZoneId = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<TimeZoneId, ErrorEvent> => {\n try {\n const fmt = new Intl.DateTimeFormat(undefined, { timeZone: value })\n return success(fmt.resolvedOptions().timeZone as TimeZoneId)\n } catch (e) {\n if (isError(e)) {\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n } else {\n throw e\n }\n }\n}\n\nexport const fromString = (value: string): TimeZoneId => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n\nexport const Utc = 'UTC' as TimeZoneId\nexport const SystemDefault = Intl.DateTimeFormat().resolvedOptions().timeZone as TimeZoneId\n"],"mappings":";AAAA,SAAS,SAAiB,eAAe;AACzC,OAAO,SAAS;AAEhB,SAAS,iBAAiB;AAC1B,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,cAAc;AAG1C,IAAM,cAAc,CAAC,UAAkD;AAC5E,MAAI;AACF,UAAM,MAAM,IAAI,KAAK,eAAe,QAAW,EAAE,UAAU,MAAM,CAAC;AAClE,WAAO,QAAQ,IAAI,gBAAgB,EAAE,QAAsB;AAAA,EAC7D,SAAS,GAAG;AACV,QAAI,QAAQ,CAAC,GAAG;AACd,aAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,EAAE,QAAQ,CAAC,CAAC;AAAA,IAClF,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAEO,IAAM,aAAa,CAAC,UAA8B;AACvD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;AAE5D,IAAM,MAAM;AACZ,IAAM,gBAAgB,KAAK,eAAe,EAAE,gBAAgB,EAAE;","names":[]}
1
+ {"version":3,"sources":["../../src/temporal/time-zone-id.ts"],"sourcesContent":["import { failure, Result, success } from '@bessemer/cornerstone/result'\nimport Zod from 'zod'\nimport { NominalType } from '@bessemer/cornerstone/types'\nimport { namespace } from '@bessemer/cornerstone/resource-key'\nimport { ErrorEvent, invalidValue, unpackResult } from '@bessemer/cornerstone/error/error-event'\nimport { isError } from '@bessemer/cornerstone/error/error'\nimport { structuredTransform } from '@bessemer/cornerstone/zod-util'\n\nexport const Namespace = namespace('time-zone-id')\nexport type TimeZoneId = NominalType<string, typeof Namespace>\n\nexport const parseString = (value: string): Result<TimeZoneId, ErrorEvent> => {\n try {\n const fmt = new Intl.DateTimeFormat(undefined, { timeZone: value })\n return success(fmt.resolvedOptions().timeZone as TimeZoneId)\n } catch (e) {\n if (isError(e)) {\n return failure(invalidValue(value, { namespace: Namespace, message: e.message }))\n } else {\n throw e\n }\n }\n}\n\nexport const fromString = (value: string): TimeZoneId => {\n return unpackResult(parseString(value))\n}\n\nexport const Schema = structuredTransform(Zod.string(), parseString)\n\nexport const Utc = 'UTC' as TimeZoneId\nexport const getSystemDefault = (): TimeZoneId => {\n return Intl.DateTimeFormat().resolvedOptions().timeZone as TimeZoneId\n}\n"],"mappings":";AAAA,SAAS,SAAiB,eAAe;AACzC,OAAO,SAAS;AAEhB,SAAS,iBAAiB;AAC1B,SAAqB,cAAc,oBAAoB;AACvD,SAAS,eAAe;AACxB,SAAS,2BAA2B;AAE7B,IAAM,YAAY,UAAU,cAAc;AAG1C,IAAM,cAAc,CAAC,UAAkD;AAC5E,MAAI;AACF,UAAM,MAAM,IAAI,KAAK,eAAe,QAAW,EAAE,UAAU,MAAM,CAAC;AAClE,WAAO,QAAQ,IAAI,gBAAgB,EAAE,QAAsB;AAAA,EAC7D,SAAS,GAAG;AACV,QAAI,QAAQ,CAAC,GAAG;AACd,aAAO,QAAQ,aAAa,OAAO,EAAE,WAAW,WAAW,SAAS,EAAE,QAAQ,CAAC,CAAC;AAAA,IAClF,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AACF;AAEO,IAAM,aAAa,CAAC,UAA8B;AACvD,SAAO,aAAa,YAAY,KAAK,CAAC;AACxC;AAEO,IAAM,SAAS,oBAAoB,IAAI,OAAO,GAAG,WAAW;AAE5D,IAAM,MAAM;AACZ,IAAM,mBAAmB,MAAkB;AAChD,SAAO,KAAK,eAAe,EAAE,gBAAgB,EAAE;AACjD;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bessemer/cornerstone",
3
3
  "type": "module",
4
- "version": "0.5.92",
4
+ "version": "0.5.93",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "sideEffects": false,