@duplojs/utils 1.4.57 → 1.4.59
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/array/group.cjs +11 -11
- package/dist/array/group.d.ts +1 -1
- package/dist/array/group.mjs +11 -11
- package/dist/clean/constraint/base.d.ts +6 -4
- package/dist/clean/constraint/defaultConstraint/index.d.ts +1 -0
- package/dist/clean/constraint/defaultConstraint/number.d.ts +6 -6
- package/dist/clean/constraint/defaultConstraint/string.d.ts +4 -4
- package/dist/clean/constraint/defaultConstraint/time.cjs +19 -0
- package/dist/clean/constraint/defaultConstraint/time.d.ts +61 -0
- package/dist/clean/constraint/defaultConstraint/time.mjs +16 -0
- package/dist/clean/constraint/set.d.ts +6 -4
- package/dist/clean/entity.d.ts +2 -1
- package/dist/clean/index.cjs +3 -0
- package/dist/clean/index.mjs +1 -0
- package/dist/clean/newType.d.ts +7 -5
- package/dist/clean/primitive/base.d.ts +25 -34
- package/dist/clean/primitive/operations/date/dateAddTime.d.ts +7 -11
- package/dist/clean/primitive/operations/date/dateGreaterThan.d.ts +9 -7
- package/dist/clean/primitive/operations/date/dateLessThan.d.ts +9 -7
- package/dist/clean/primitive/operations/date/dateMax.d.ts +3 -10
- package/dist/clean/primitive/operations/date/dateMin.d.ts +3 -10
- package/dist/clean/primitive/operations/date/dateSubtractTime.d.ts +7 -11
- package/dist/clean/primitive/operations/equal.cjs +1 -1
- package/dist/clean/primitive/operations/equal.d.ts +3 -3
- package/dist/clean/primitive/operations/equal.mjs +1 -1
- package/dist/clean/primitive/operations/sort.d.ts +8 -10
- package/dist/clean/primitive/operations/time/timeGreaterThan.d.ts +11 -9
- package/dist/clean/primitive/operations/time/timeLessThan.d.ts +11 -9
- package/dist/clean/primitive/operations/time/timeMax.cjs +2 -2
- package/dist/clean/primitive/operations/time/timeMax.d.ts +10 -17
- package/dist/clean/primitive/operations/time/timeMax.mjs +2 -2
- package/dist/clean/primitive/operations/time/timeMin.cjs +3 -3
- package/dist/clean/primitive/operations/time/timeMin.d.ts +10 -17
- package/dist/clean/primitive/operations/time/timeMin.mjs +3 -3
- package/dist/clean/unwrapEntity.cjs +13 -3
- package/dist/clean/unwrapEntity.d.ts +57 -5
- package/dist/clean/unwrapEntity.mjs +13 -3
- package/dist/common/index.d.ts +3 -4
- package/dist/common/kind.d.ts +1 -0
- package/dist/common/path.cjs +13 -13
- package/dist/common/path.d.ts +17 -11
- package/dist/common/path.mjs +13 -13
- package/dist/common/toRegExp.cjs +19 -0
- package/dist/common/toRegExp.d.ts +31 -0
- package/dist/common/toRegExp.mjs +17 -0
- package/dist/common/transformer.cjs +45 -0
- package/dist/common/transformer.d.ts +61 -0
- package/dist/common/transformer.mjs +40 -0
- package/dist/common/types/DeepReadonly.d.ts +1 -1
- package/dist/common/types/toLargeEnsemble.d.ts +2 -2
- package/dist/dataParser/error.cjs +4 -2
- package/dist/dataParser/error.d.ts +4 -2
- package/dist/dataParser/error.mjs +4 -2
- package/dist/dataParser/extended/date.d.ts +9 -4
- package/dist/dataParser/extended/time.d.ts +28 -12
- package/dist/dataParser/identifier.d.ts +20 -8
- package/dist/dataParser/parsers/date.cjs +16 -12
- package/dist/dataParser/parsers/date.d.ts +15 -9
- package/dist/dataParser/parsers/date.mjs +16 -12
- package/dist/dataParser/parsers/time/checkers/max.cjs +3 -0
- package/dist/dataParser/parsers/time/checkers/max.d.ts +28 -0
- package/dist/dataParser/parsers/time/checkers/max.mjs +3 -0
- package/dist/dataParser/parsers/time/checkers/min.cjs +3 -0
- package/dist/dataParser/parsers/time/checkers/min.d.ts +28 -0
- package/dist/dataParser/parsers/time/checkers/min.mjs +3 -0
- package/dist/dataParser/parsers/time/index.cjs +14 -10
- package/dist/dataParser/parsers/time/index.d.ts +15 -9
- package/dist/dataParser/parsers/time/index.mjs +14 -10
- package/dist/date/applyTimezone.cjs +4 -4
- package/dist/date/applyTimezone.d.ts +18 -16
- package/dist/date/applyTimezone.mjs +2 -2
- package/dist/date/closestTo.cjs +6 -2
- package/dist/date/closestTo.d.ts +15 -15
- package/dist/date/closestTo.mjs +6 -2
- package/dist/date/constants.cjs +4 -4
- package/dist/date/constants.d.ts +2 -2
- package/dist/date/constants.mjs +3 -3
- package/dist/date/create.cjs +20 -10
- package/dist/date/create.d.ts +24 -38
- package/dist/date/create.mjs +21 -11
- package/dist/date/createOrThrow.d.ts +18 -20
- package/dist/date/createTime.cjs +16 -7
- package/dist/date/createTime.d.ts +19 -18
- package/dist/date/createTime.mjs +17 -8
- package/dist/date/createTimeOrThrow.d.ts +17 -20
- package/dist/date/each.cjs +6 -4
- package/dist/date/each.d.ts +21 -19
- package/dist/date/each.mjs +6 -4
- package/dist/date/format.d.ts +17 -15
- package/dist/date/formatTime.d.ts +17 -16
- package/dist/date/getTimezoneOffset.cjs +6 -3
- package/dist/date/getTimezoneOffset.d.ts +17 -18
- package/dist/date/getTimezoneOffset.mjs +6 -3
- package/dist/date/getters/getDayOfMonth.cjs +3 -3
- package/dist/date/getters/getDayOfMonth.d.ts +20 -14
- package/dist/date/getters/getDayOfMonth.mjs +3 -3
- package/dist/date/getters/getDayOfWeek.cjs +3 -3
- package/dist/date/getters/getDayOfWeek.d.ts +15 -12
- package/dist/date/getters/getDayOfWeek.mjs +3 -3
- package/dist/date/getters/getDayOfYear.cjs +6 -6
- package/dist/date/getters/getDayOfYear.d.ts +21 -13
- package/dist/date/getters/getDayOfYear.mjs +6 -6
- package/dist/date/getters/getFirstDayOfMonth.cjs +2 -3
- package/dist/date/getters/getFirstDayOfMonth.d.ts +16 -10
- package/dist/date/getters/getFirstDayOfMonth.mjs +2 -3
- package/dist/date/getters/getFirstDayOfWeek.cjs +2 -3
- package/dist/date/getters/getFirstDayOfWeek.d.ts +17 -10
- package/dist/date/getters/getFirstDayOfWeek.mjs +2 -3
- package/dist/date/getters/getHour.cjs +3 -3
- package/dist/date/getters/getHour.d.ts +16 -14
- package/dist/date/getters/getHour.mjs +3 -3
- package/dist/date/getters/getLastDayOfMonth.cjs +2 -3
- package/dist/date/getters/getLastDayOfMonth.d.ts +16 -10
- package/dist/date/getters/getLastDayOfMonth.mjs +2 -3
- package/dist/date/getters/getLastDayOfWeek.cjs +2 -3
- package/dist/date/getters/getLastDayOfWeek.d.ts +17 -10
- package/dist/date/getters/getLastDayOfWeek.mjs +2 -3
- package/dist/date/getters/getMilliseconds.cjs +2 -2
- package/dist/date/getters/getMilliseconds.d.ts +11 -9
- package/dist/date/getters/getMilliseconds.mjs +2 -2
- package/dist/date/getters/getMinute.cjs +3 -3
- package/dist/date/getters/getMinute.d.ts +17 -15
- package/dist/date/getters/getMinute.mjs +3 -3
- package/dist/date/getters/getMonth.cjs +3 -3
- package/dist/date/getters/getMonth.d.ts +20 -15
- package/dist/date/getters/getMonth.mjs +3 -3
- package/dist/date/getters/getSecond.cjs +3 -3
- package/dist/date/getters/getSecond.d.ts +17 -15
- package/dist/date/getters/getSecond.mjs +3 -3
- package/dist/date/getters/getWeekOfYear.cjs +12 -11
- package/dist/date/getters/getWeekOfYear.d.ts +17 -11
- package/dist/date/getters/getWeekOfYear.mjs +12 -11
- package/dist/date/getters/getYear.cjs +3 -3
- package/dist/date/getters/getYear.d.ts +16 -15
- package/dist/date/getters/getYear.mjs +3 -3
- package/dist/date/index.cjs +12 -6
- package/dist/date/index.d.ts +5 -2
- package/dist/date/index.mjs +6 -3
- package/dist/date/is.cjs +3 -8
- package/dist/date/is.d.ts +9 -14
- package/dist/date/is.mjs +3 -8
- package/dist/date/isSafeTimeValue.d.ts +9 -13
- package/dist/date/isSafeTimestamp.d.ts +7 -16
- package/dist/date/isSerializedTheDate.cjs +20 -0
- package/dist/date/isSerializedTheDate.d.ts +31 -0
- package/dist/date/isSerializedTheDate.mjs +18 -0
- package/dist/date/isSerializedTheTime.cjs +20 -0
- package/dist/date/isSerializedTheTime.d.ts +31 -0
- package/dist/date/isSerializedTheTime.mjs +18 -0
- package/dist/date/isTime.cjs +3 -8
- package/dist/date/isTime.d.ts +7 -14
- package/dist/date/isTime.mjs +3 -8
- package/dist/date/kind.cjs +9 -0
- package/dist/date/kind.d.ts +1 -0
- package/dist/date/kind.mjs +7 -0
- package/dist/date/makeSafeTimeValue.d.ts +12 -11
- package/dist/date/makeSafeTimestamp.d.ts +12 -11
- package/dist/date/max.cjs +2 -2
- package/dist/date/max.d.ts +13 -13
- package/dist/date/max.mjs +2 -2
- package/dist/date/maxTime.cjs +2 -2
- package/dist/date/maxTime.d.ts +13 -21
- package/dist/date/maxTime.mjs +2 -2
- package/dist/date/min.cjs +2 -2
- package/dist/date/min.d.ts +13 -13
- package/dist/date/min.mjs +2 -2
- package/dist/date/minTime.cjs +2 -2
- package/dist/date/minTime.d.ts +13 -21
- package/dist/date/minTime.mjs +2 -2
- package/dist/date/now.cjs +3 -1
- package/dist/date/now.d.ts +9 -7
- package/dist/date/now.mjs +3 -1
- package/dist/date/operators/addDays.cjs +3 -5
- package/dist/date/operators/addDays.d.ts +14 -11
- package/dist/date/operators/addDays.mjs +3 -5
- package/dist/date/operators/addHours.cjs +3 -5
- package/dist/date/operators/addHours.d.ts +14 -11
- package/dist/date/operators/addHours.mjs +3 -5
- package/dist/date/operators/addMilliseconds.cjs +3 -5
- package/dist/date/operators/addMilliseconds.d.ts +14 -11
- package/dist/date/operators/addMilliseconds.mjs +3 -5
- package/dist/date/operators/addMinutes.cjs +3 -5
- package/dist/date/operators/addMinutes.d.ts +14 -11
- package/dist/date/operators/addMinutes.mjs +3 -5
- package/dist/date/operators/addMonths.cjs +2 -2
- package/dist/date/operators/addMonths.d.ts +13 -13
- package/dist/date/operators/addMonths.mjs +2 -2
- package/dist/date/operators/addSeconds.cjs +3 -5
- package/dist/date/operators/addSeconds.d.ts +14 -11
- package/dist/date/operators/addSeconds.mjs +3 -5
- package/dist/date/operators/addTime.cjs +13 -6
- package/dist/date/operators/addTime.d.ts +20 -18
- package/dist/date/operators/addTime.mjs +13 -6
- package/dist/date/operators/addWeeks.cjs +6 -5
- package/dist/date/operators/addWeeks.d.ts +14 -11
- package/dist/date/operators/addWeeks.mjs +6 -5
- package/dist/date/operators/addYears.cjs +2 -2
- package/dist/date/operators/addYears.d.ts +13 -13
- package/dist/date/operators/addYears.mjs +2 -2
- package/dist/date/operators/between.d.ts +11 -11
- package/dist/date/operators/betweenThan.d.ts +11 -11
- package/dist/date/operators/betweenThanTime.d.ts +18 -22
- package/dist/date/operators/betweenTime.d.ts +17 -21
- package/dist/date/operators/greater.d.ts +12 -9
- package/dist/date/operators/greaterThan.d.ts +14 -11
- package/dist/date/operators/greaterThanTime.d.ts +17 -21
- package/dist/date/operators/greaterTime.d.ts +16 -20
- package/dist/date/operators/less.d.ts +12 -9
- package/dist/date/operators/lessThan.d.ts +13 -10
- package/dist/date/operators/lessThanTime.d.ts +17 -21
- package/dist/date/operators/lessTime.d.ts +16 -20
- package/dist/date/operators/subtractDays.cjs +3 -5
- package/dist/date/operators/subtractDays.d.ts +14 -11
- package/dist/date/operators/subtractDays.mjs +3 -5
- package/dist/date/operators/subtractHours.cjs +3 -5
- package/dist/date/operators/subtractHours.d.ts +14 -11
- package/dist/date/operators/subtractHours.mjs +3 -5
- package/dist/date/operators/subtractMilliseconds.cjs +3 -5
- package/dist/date/operators/subtractMilliseconds.d.ts +14 -11
- package/dist/date/operators/subtractMilliseconds.mjs +3 -5
- package/dist/date/operators/subtractMinutes.cjs +3 -5
- package/dist/date/operators/subtractMinutes.d.ts +14 -11
- package/dist/date/operators/subtractMinutes.mjs +3 -5
- package/dist/date/operators/subtractMonths.cjs +2 -2
- package/dist/date/operators/subtractMonths.d.ts +17 -11
- package/dist/date/operators/subtractMonths.mjs +2 -2
- package/dist/date/operators/subtractSeconds.cjs +3 -5
- package/dist/date/operators/subtractSeconds.d.ts +14 -11
- package/dist/date/operators/subtractSeconds.mjs +3 -5
- package/dist/date/operators/subtractTime.cjs +13 -6
- package/dist/date/operators/subtractTime.d.ts +20 -18
- package/dist/date/operators/subtractTime.mjs +13 -6
- package/dist/date/operators/subtractWeeks.cjs +3 -5
- package/dist/date/operators/subtractWeeks.d.ts +14 -11
- package/dist/date/operators/subtractWeeks.mjs +3 -5
- package/dist/date/operators/subtractYears.cjs +2 -2
- package/dist/date/operators/subtractYears.d.ts +17 -11
- package/dist/date/operators/subtractYears.mjs +2 -2
- package/dist/date/round.cjs +2 -2
- package/dist/date/round.d.ts +11 -14
- package/dist/date/round.mjs +2 -2
- package/dist/date/serialize.cjs +14 -0
- package/dist/date/serialize.d.ts +41 -0
- package/dist/date/serialize.mjs +12 -0
- package/dist/date/sort.cjs +2 -2
- package/dist/date/sort.d.ts +16 -15
- package/dist/date/sort.mjs +2 -2
- package/dist/date/sortTimes.cjs +2 -2
- package/dist/date/sortTimes.d.ts +15 -21
- package/dist/date/sortTimes.mjs +2 -2
- package/dist/date/theDate.cjs +124 -0
- package/dist/date/theDate.d.ts +114 -0
- package/dist/date/theDate.mjs +122 -0
- package/dist/date/theTime.cjs +36 -0
- package/dist/date/theTime.d.ts +53 -0
- package/dist/date/theTime.mjs +34 -0
- package/dist/date/timezone.cjs +3 -0
- package/dist/date/timezone.d.ts +27 -0
- package/dist/date/timezone.mjs +3 -0
- package/dist/date/toISOString.cjs +5 -2
- package/dist/date/toISOString.d.ts +12 -10
- package/dist/date/toISOString.mjs +5 -2
- package/dist/date/toNative.cjs +4 -0
- package/dist/date/toNative.d.ts +12 -10
- package/dist/date/toNative.mjs +4 -0
- package/dist/date/toTimeValue.cjs +6 -2
- package/dist/date/toTimeValue.d.ts +14 -12
- package/dist/date/toTimeValue.mjs +6 -2
- package/dist/date/toTimestamp.cjs +5 -3
- package/dist/date/toTimestamp.d.ts +11 -9
- package/dist/date/toTimestamp.mjs +6 -4
- package/dist/date/today.cjs +3 -1
- package/dist/date/today.d.ts +14 -7
- package/dist/date/today.mjs +3 -1
- package/dist/date/tomorrow.cjs +2 -1
- package/dist/date/tomorrow.d.ts +12 -7
- package/dist/date/tomorrow.mjs +2 -1
- package/dist/date/types/index.d.ts +2 -2
- package/dist/date/types/serializedTheDate.d.ts +1 -0
- package/dist/date/types/serializedTheTime.d.ts +42 -0
- package/dist/date/types/spoolingDate.d.ts +2 -1
- package/dist/date/yesterday.cjs +2 -1
- package/dist/date/yesterday.d.ts +12 -7
- package/dist/date/yesterday.mjs +2 -1
- package/dist/generator/asyncGroup.cjs +31 -0
- package/dist/generator/asyncGroup.d.ts +39 -0
- package/dist/generator/asyncGroup.mjs +29 -0
- package/dist/generator/group.cjs +39 -0
- package/dist/generator/group.d.ts +101 -0
- package/dist/generator/group.mjs +36 -0
- package/dist/generator/index.cjs +5 -0
- package/dist/generator/index.d.ts +3 -0
- package/dist/generator/index.mjs +2 -0
- package/dist/index.cjs +7 -6
- package/dist/index.mjs +2 -3
- package/dist/metadata.json +94 -40
- package/dist/object/entries.cjs +7 -2
- package/dist/object/entries.mjs +7 -2
- package/dist/object/keys.cjs +7 -2
- package/dist/object/keys.d.ts +1 -1
- package/dist/object/keys.mjs +7 -2
- package/package.json +1 -1
- package/dist/common/toJSON.cjs +0 -37
- package/dist/common/toJSON.d.ts +0 -44
- package/dist/common/toJSON.mjs +0 -35
- package/dist/common/toString.cjs +0 -10
- package/dist/common/toString.d.ts +0 -17
- package/dist/common/toString.mjs +0 -8
- package/dist/common/toTransform.cjs +0 -37
- package/dist/common/toTransform.d.ts +0 -50
- package/dist/common/toTransform.mjs +0 -35
- package/dist/date/createTheDate.cjs +0 -13
- package/dist/date/createTheDate.d.ts +0 -28
- package/dist/date/createTheDate.mjs +0 -11
- package/dist/date/createTheTime.cjs +0 -13
- package/dist/date/createTheTime.d.ts +0 -25
- package/dist/date/createTheTime.mjs +0 -11
- package/dist/date/types/theDate.d.ts +0 -11
- package/dist/date/types/theTime.d.ts +0 -10
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type IsEqual, type And } from "../common";
|
|
2
2
|
import { type maxTimeValue, type minTimeValue } from "./constants";
|
|
3
|
-
import { type
|
|
3
|
+
import { type SerializedTheTime, type SpoolingTime } from "./types";
|
|
4
4
|
import * as DEither from "../either";
|
|
5
5
|
import { type IsGreater, type IsLess } from "../number";
|
|
6
|
+
import { TheTime } from "./theTime";
|
|
6
7
|
export type MayBeTime = DEither.Right<"time-created", TheTime> | DEither.Left<"time-created-error", null>;
|
|
7
8
|
type Units = "week" | "day" | "hour" | "minute" | "second" | "millisecond";
|
|
8
9
|
declare const SymbolForbiddenTime: unique symbol;
|
|
@@ -40,42 +41,42 @@ type ForbiddenTime<GenericInput extends number, GenericUnit extends Units> = IsE
|
|
|
40
41
|
[SymbolForbiddenTime]: "Support that the weeks between -14892855 and 14892855.";
|
|
41
42
|
} : GenericInput));
|
|
42
43
|
/**
|
|
43
|
-
* Creates a TheTime
|
|
44
|
+
* Creates a `TheTime` (normalized duration) from numeric or structured inputs.
|
|
44
45
|
*
|
|
45
|
-
* Signature: `createTime(input, unit?)` →
|
|
46
|
+
* Signature: `createTime(input, unit?)` → `TheTime | Either<"time-created", TheTime>`
|
|
46
47
|
*
|
|
47
|
-
* The
|
|
48
|
+
* The return type depends on the overload:
|
|
49
|
+
* - Literal `number + unit` overload returns `TheTime` directly.
|
|
50
|
+
* - Runtime inputs (`number`, `SerializedTheTime`, `SpoolingTime`, `TheTime`) can return `Either`.
|
|
48
51
|
*
|
|
49
52
|
* ```ts
|
|
50
|
-
* const
|
|
51
|
-
* //
|
|
53
|
+
* const direct = D.createTime(90, "minute");
|
|
54
|
+
* // direct: TheTime
|
|
52
55
|
*
|
|
53
|
-
* const
|
|
54
|
-
*
|
|
55
|
-
* minute: 15,
|
|
56
|
-
* });
|
|
57
|
-
* // Either<"time-created", TheTime>
|
|
56
|
+
* const mayBeFromSerialized = D.createTime("time5400000+");
|
|
57
|
+
* // mayBeFromSerialized: Either<"time-created", TheTime>
|
|
58
58
|
*
|
|
59
|
-
* const
|
|
59
|
+
* const mayBeFromSpooling = D.createTime({
|
|
60
60
|
* value: "+01:30:00",
|
|
61
|
+
* minute: 15,
|
|
61
62
|
* });
|
|
62
|
-
* // Either<"time-created", TheTime>
|
|
63
|
+
* // mayBeFromSpooling: Either<"time-created", TheTime>
|
|
63
64
|
*
|
|
64
|
-
*
|
|
65
|
+
* pipe(
|
|
65
66
|
* 120,
|
|
66
67
|
* D.createTime,
|
|
67
|
-
* );
|
|
68
|
-
* // piped: Either<"time-created", TheTime>
|
|
68
|
+
* ); // Either<"time-created", TheTime>
|
|
69
69
|
* ```
|
|
70
70
|
*
|
|
71
71
|
* @remarks
|
|
72
|
-
* -
|
|
72
|
+
* - `TheTime` represents a duration, not a calendar date.
|
|
73
73
|
*
|
|
74
74
|
* @see https://utils.duplojs.dev/en/v1/api/date/createTime
|
|
75
|
+
* @see https://utils.duplojs.dev/en/v1/api/date/createTimeOrThrow
|
|
75
76
|
*
|
|
76
77
|
* @namespace D
|
|
77
78
|
*
|
|
78
79
|
*/
|
|
79
80
|
export declare function createTime<GenericInput extends number, GenericUnit extends Units = "millisecond">(input: GenericInput & ForbiddenTime<GenericInput, GenericUnit>, unit: GenericUnit): TheTime;
|
|
80
|
-
export declare function createTime<GenericInput extends number | TheTime | SpoolingTime>(input: GenericInput): MayBeTime;
|
|
81
|
+
export declare function createTime<GenericInput extends number | TheTime | SpoolingTime | SerializedTheTime>(input: GenericInput): MayBeTime;
|
|
81
82
|
export {};
|
package/dist/date/createTime.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createTheTime } from './createTheTime.mjs';
|
|
1
|
+
import { millisecondsInOneSecond, millisecondInOneMinute, millisecondInOneHour, millisecondsInOneDay, millisecondInOneWeek, serializeTheTimeRegex, isoTimeRegex } from './constants.mjs';
|
|
3
2
|
import { isSafeTimeValue } from './isSafeTimeValue.mjs';
|
|
4
|
-
import {
|
|
3
|
+
import { TheTime } from './theTime.mjs';
|
|
5
4
|
import { left } from '../either/left/create.mjs';
|
|
6
5
|
import { right } from '../either/right/create.mjs';
|
|
7
6
|
|
|
@@ -14,14 +13,24 @@ const unitsMapper = {
|
|
|
14
13
|
millisecond: 1,
|
|
15
14
|
};
|
|
16
15
|
function createTime(input, unit) {
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
16
|
+
if (input instanceof TheTime) {
|
|
17
|
+
return input;
|
|
19
18
|
}
|
|
20
19
|
if (typeof input === "number") {
|
|
20
|
+
if (unit) {
|
|
21
|
+
return TheTime.new(input * unitsMapper[unit]);
|
|
22
|
+
}
|
|
21
23
|
return createFromTimeValue(input * unitsMapper[unit ?? "millisecond"]);
|
|
22
24
|
}
|
|
23
|
-
if (typeof input === "string"
|
|
24
|
-
|
|
25
|
+
if (typeof input === "string") {
|
|
26
|
+
const serializeTheTimeMatch = input.match(serializeTheTimeRegex);
|
|
27
|
+
if (!serializeTheTimeMatch) {
|
|
28
|
+
return left("time-created-error", null);
|
|
29
|
+
}
|
|
30
|
+
const { value, sign } = serializeTheTimeMatch.groups;
|
|
31
|
+
return createFromTimeValue(Number(sign === "-"
|
|
32
|
+
? `-${value}`
|
|
33
|
+
: value));
|
|
25
34
|
}
|
|
26
35
|
const { value = 0, week = 0, day = 0, hour = 0, minute = 0, second = 0, millisecond = 0, } = input;
|
|
27
36
|
let fromValue = 0;
|
|
@@ -53,7 +62,7 @@ function createFromTimeValue(input) {
|
|
|
53
62
|
if (!isSafeTimeValue(input)) {
|
|
54
63
|
return left("time-created-error", null);
|
|
55
64
|
}
|
|
56
|
-
return right("time-created",
|
|
65
|
+
return right("time-created", TheTime.new(input));
|
|
57
66
|
}
|
|
58
67
|
|
|
59
68
|
export { createTime };
|
|
@@ -1,45 +1,42 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SerializedTheTime, SpoolingTime } from "./types";
|
|
2
|
+
import { type TheTime } from "./theTime";
|
|
2
3
|
declare const CreateTheTimeError_base: new (params: {
|
|
3
4
|
"@DuplojsUtilsError/create-the-time-error"?: unknown;
|
|
4
5
|
}, parentParams: readonly [message?: string | undefined, options?: ErrorOptions | undefined]) => Error & import("../common").Kind<import("../common").KindDefinition<"create-the-time-error", unknown>, unknown> & import("../common").Kind<import("../common").KindDefinition<"@DuplojsUtilsError/create-the-time-error", unknown>, unknown>;
|
|
5
6
|
export declare class CreateTheTimeError extends CreateTheTimeError_base {
|
|
6
|
-
input: TheTime | number | SpoolingTime;
|
|
7
|
-
constructor(input: TheTime | number | SpoolingTime);
|
|
7
|
+
input: TheTime | number | SpoolingTime | SerializedTheTime;
|
|
8
|
+
constructor(input: TheTime | number | SpoolingTime | SerializedTheTime);
|
|
8
9
|
}
|
|
9
10
|
/**
|
|
10
|
-
* Creates a TheTime
|
|
11
|
+
* Creates a `TheTime` and throws when input is invalid.
|
|
11
12
|
*
|
|
12
|
-
* Signature: `createTimeOrThrow(input)` →
|
|
13
|
-
*
|
|
14
|
-
* The input value is not mutated.
|
|
13
|
+
* Signature: `createTimeOrThrow(input)` → `TheTime`
|
|
15
14
|
*
|
|
16
15
|
* ```ts
|
|
17
|
-
* const
|
|
18
|
-
*
|
|
19
|
-
* // result: "time90000+"
|
|
16
|
+
* const fromNumber = D.createTimeOrThrow(90_000);
|
|
17
|
+
* // fromNumber: TheTime
|
|
20
18
|
*
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
* // result2: "time3600000+"
|
|
19
|
+
* const fromSerialized = D.createTimeOrThrow("time3600000+");
|
|
20
|
+
* // fromSerialized: TheTime
|
|
24
21
|
*
|
|
25
|
-
* const
|
|
22
|
+
* const fromSpooling = D.createTimeOrThrow({
|
|
26
23
|
* hour: 1,
|
|
27
24
|
* minute: 30,
|
|
28
|
-
* };
|
|
29
|
-
*
|
|
30
|
-
* // result3: "time5400000+"
|
|
25
|
+
* });
|
|
26
|
+
* // fromSpooling: TheTime
|
|
31
27
|
*
|
|
32
28
|
* pipe(
|
|
33
|
-
*
|
|
29
|
+
* fromNumber,
|
|
34
30
|
* ```
|
|
35
31
|
*
|
|
36
32
|
* @remarks
|
|
37
|
-
* - Throws
|
|
33
|
+
* - Throws `CreateTheTimeError` on invalid input.
|
|
38
34
|
*
|
|
39
35
|
* @see https://utils.duplojs.dev/en/v1/api/date/createTimeOrThrow
|
|
36
|
+
* @see https://utils.duplojs.dev/en/v1/api/date/createTime
|
|
40
37
|
*
|
|
41
38
|
* @namespace D
|
|
42
39
|
*
|
|
43
40
|
*/
|
|
44
|
-
export declare function createTimeOrThrow(input: number | TheTime | SpoolingTime): TheTime;
|
|
41
|
+
export declare function createTimeOrThrow(input: number | TheTime | SpoolingTime | SerializedTheTime): TheTime;
|
|
45
42
|
export {};
|
package/dist/date/each.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var loop = require('../generator/loop.cjs');
|
|
4
4
|
var constants = require('./constants.cjs');
|
|
5
5
|
var toTimestamp = require('./toTimestamp.cjs');
|
|
6
|
-
var
|
|
6
|
+
var theDate = require('./theDate.cjs');
|
|
7
7
|
|
|
8
8
|
const stepMapper = {
|
|
9
9
|
millisecond: (timestamp, direction) => timestamp + direction,
|
|
@@ -32,7 +32,9 @@ function each(range, unit = "day") {
|
|
|
32
32
|
const advanceTimestamp = stepMapper[unit];
|
|
33
33
|
return loop.loop(({ exit, next, previousOutput, }) => {
|
|
34
34
|
if (!previousOutput) {
|
|
35
|
-
return
|
|
35
|
+
return range.start instanceof theDate.TheDate
|
|
36
|
+
? next(range.start)
|
|
37
|
+
: next(theDate.TheDate.new(toTimestamp.toTimestamp(range.start)));
|
|
36
38
|
}
|
|
37
39
|
const currentTimestamp = advanceTimestamp(toTimestamp.toTimestamp(previousOutput), direction);
|
|
38
40
|
const isWithinRange = direction === 1
|
|
@@ -40,10 +42,10 @@ function each(range, unit = "day") {
|
|
|
40
42
|
: currentTimestamp > endTimestamp;
|
|
41
43
|
if (!isWithinRange) {
|
|
42
44
|
return exit(currentTimestamp === endTimestamp
|
|
43
|
-
?
|
|
45
|
+
? theDate.TheDate.new(currentTimestamp)
|
|
44
46
|
: undefined);
|
|
45
47
|
}
|
|
46
|
-
return next(
|
|
48
|
+
return next(theDate.TheDate.new(currentTimestamp));
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
|
package/dist/date/each.d.ts
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TheDate } from "./theDate";
|
|
2
|
+
import type { Unit, SerializedTheDate } from "./types";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
+
* Creates an iterator over a date range with a chosen unit step.
|
|
4
5
|
*
|
|
5
|
-
* Signature: `each(range, unit)` →
|
|
6
|
-
*
|
|
7
|
-
* The input value is not mutated.
|
|
6
|
+
* Signature: `each(range, unit?)` → `Iterator<TheDate>`
|
|
8
7
|
*
|
|
9
8
|
* ```ts
|
|
10
|
-
* const
|
|
9
|
+
* const range = {
|
|
11
10
|
* start: D.create("2024-06-01"),
|
|
12
11
|
* end: D.create("2024-06-03"),
|
|
13
12
|
* } as const;
|
|
14
13
|
*
|
|
15
|
-
* const iterator = D.each(
|
|
16
|
-
* const
|
|
17
|
-
* //
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
14
|
+
* const iterator = D.each(range, "day");
|
|
15
|
+
* const values = A.from(iterator);
|
|
16
|
+
* // values: TheDate[]
|
|
17
|
+
*
|
|
18
|
+
* const reverse = A.from(
|
|
19
|
+
* D.each({
|
|
20
|
+
* start: D.create("2024-06-03"),
|
|
21
|
+
* end: D.create("2024-06-01"),
|
|
22
|
+
* }),
|
|
23
|
+
* );
|
|
24
|
+
* // reverse: TheDate[]
|
|
24
25
|
* ```
|
|
25
26
|
*
|
|
26
27
|
* @remarks
|
|
27
|
-
* -
|
|
28
|
+
* - Supports ascending and descending ranges.
|
|
29
|
+
* - Includes the end value when exactly aligned with step boundaries.
|
|
28
30
|
*
|
|
29
31
|
* @see https://utils.duplojs.dev/en/v1/api/date/each
|
|
30
32
|
*
|
|
@@ -32,6 +34,6 @@ import type { TheDate, Unit } from "./types";
|
|
|
32
34
|
*
|
|
33
35
|
*/
|
|
34
36
|
export declare function each(range: {
|
|
35
|
-
start: TheDate;
|
|
36
|
-
end: TheDate;
|
|
37
|
-
}, unit?: Unit): Generator
|
|
37
|
+
start: TheDate | SerializedTheDate;
|
|
38
|
+
end: TheDate | SerializedTheDate;
|
|
39
|
+
}, unit?: Unit): Generator<TheDate, unknown, unknown>;
|
package/dist/date/each.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { loop } from '../generator/loop.mjs';
|
|
2
2
|
import { millisecondsInOneDay, millisecondInOneHour, millisecondInOneMinute, millisecondsInOneSecond } from './constants.mjs';
|
|
3
3
|
import { toTimestamp } from './toTimestamp.mjs';
|
|
4
|
-
import {
|
|
4
|
+
import { TheDate } from './theDate.mjs';
|
|
5
5
|
|
|
6
6
|
const stepMapper = {
|
|
7
7
|
millisecond: (timestamp, direction) => timestamp + direction,
|
|
@@ -30,7 +30,9 @@ function each(range, unit = "day") {
|
|
|
30
30
|
const advanceTimestamp = stepMapper[unit];
|
|
31
31
|
return loop(({ exit, next, previousOutput, }) => {
|
|
32
32
|
if (!previousOutput) {
|
|
33
|
-
return
|
|
33
|
+
return range.start instanceof TheDate
|
|
34
|
+
? next(range.start)
|
|
35
|
+
: next(TheDate.new(toTimestamp(range.start)));
|
|
34
36
|
}
|
|
35
37
|
const currentTimestamp = advanceTimestamp(toTimestamp(previousOutput), direction);
|
|
36
38
|
const isWithinRange = direction === 1
|
|
@@ -38,10 +40,10 @@ function each(range, unit = "day") {
|
|
|
38
40
|
: currentTimestamp > endTimestamp;
|
|
39
41
|
if (!isWithinRange) {
|
|
40
42
|
return exit(currentTimestamp === endTimestamp
|
|
41
|
-
?
|
|
43
|
+
? TheDate.new(currentTimestamp)
|
|
42
44
|
: undefined);
|
|
43
45
|
}
|
|
44
|
-
return next(
|
|
46
|
+
return next(TheDate.new(currentTimestamp));
|
|
45
47
|
});
|
|
46
48
|
}
|
|
47
49
|
|
package/dist/date/format.d.ts
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TheDate } from "./theDate";
|
|
2
2
|
import type { Timezone } from "./timezone";
|
|
3
|
+
import type { SerializedTheDate } from "./types";
|
|
3
4
|
/**
|
|
4
|
-
* Formats a date.
|
|
5
|
+
* Formats a date with custom tokens in a target timezone.
|
|
5
6
|
*
|
|
6
7
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `format(input, formatString, timezone)` →
|
|
8
|
-
* - Curried: `format(formatString, timezone)` →
|
|
8
|
+
* - Classic: `format(input, formatString, timezone)` → `string`
|
|
9
|
+
* - Curried: `format(formatString, timezone)` → `(input) => string`
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* `input` accepts `TheDate` or `SerializedTheDate`.
|
|
11
12
|
*
|
|
12
13
|
* ```ts
|
|
13
|
-
* const
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* const input = D.create("2024-01-01", {
|
|
15
|
+
* hour: "00",
|
|
16
|
+
* minute: "00",
|
|
17
|
+
* second: "00",
|
|
18
|
+
* millisecond: "123",
|
|
19
|
+
* });
|
|
16
20
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* D.format("YYYY-MM-DD HH:mm:ss.SSS ZZ", "UTC"),
|
|
20
|
-
* ); // fullFormat: "2024-01-01 00:00:00.123 UTC"
|
|
21
|
+
* const full = D.format(input, "YYYY-MM-DD HH:mm:ss.SSS ZZ", "UTC");
|
|
22
|
+
* // full: string
|
|
21
23
|
*
|
|
22
24
|
* ```
|
|
23
25
|
*
|
|
24
26
|
* @remarks
|
|
25
|
-
* -
|
|
27
|
+
* - Supported tokens: `YYYY`, `YY`, `MM`, `DD`, `HH`, `mm`, `ss`, `SSS`, `ZZ`.
|
|
26
28
|
*
|
|
27
29
|
* @see https://utils.duplojs.dev/en/v1/api/date/format
|
|
28
30
|
*
|
|
29
31
|
* @namespace D
|
|
30
32
|
*
|
|
31
33
|
*/
|
|
32
|
-
export declare function format<GenericInput extends TheDate, GenericFormat extends string, GenericTimezone extends Timezone>(formatString: GenericFormat, timezone: GenericTimezone): (input: GenericInput) => string;
|
|
33
|
-
export declare function format<GenericInput extends TheDate, GenericFormat extends string, GenericTimezone extends Timezone>(input: GenericInput, formatString: GenericFormat, timezone: GenericTimezone): string;
|
|
34
|
+
export declare function format<GenericInput extends TheDate | SerializedTheDate, GenericFormat extends string, GenericTimezone extends Timezone>(formatString: GenericFormat, timezone: GenericTimezone): (input: GenericInput) => string;
|
|
35
|
+
export declare function format<GenericInput extends TheDate | SerializedTheDate, GenericFormat extends string, GenericTimezone extends Timezone>(input: GenericInput, formatString: GenericFormat, timezone: GenericTimezone): string;
|
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type TheTime } from "./theTime";
|
|
2
|
+
import type { SerializedTheTime } from "./types";
|
|
2
3
|
/**
|
|
3
|
-
* Formats a time.
|
|
4
|
+
* Formats a duration value with custom time tokens.
|
|
4
5
|
*
|
|
5
6
|
* **Supported call styles:**
|
|
6
|
-
* - Classic: `formatTime(input, formatString)` →
|
|
7
|
-
* - Curried: `formatTime(formatString)` →
|
|
7
|
+
* - Classic: `formatTime(input, formatString)` → `string`
|
|
8
|
+
* - Curried: `formatTime(formatString)` → `(input) => string`
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* `input` accepts `TheTime` or `SerializedTheTime`.
|
|
10
11
|
*
|
|
11
12
|
* ```ts
|
|
12
|
-
* const
|
|
13
|
-
* const
|
|
14
|
-
* //
|
|
13
|
+
* const input = D.createTime(788_645_006, "millisecond");
|
|
14
|
+
* const full = D.formatTime(input, "WW DD HH:mm:ss.SSS");
|
|
15
|
+
* // full: string
|
|
15
16
|
*
|
|
16
17
|
* pipe(
|
|
17
|
-
*
|
|
18
|
+
* input,
|
|
18
19
|
* D.formatTime("HH:mm"),
|
|
19
|
-
* ); //
|
|
20
|
+
* ); // string
|
|
20
21
|
*
|
|
21
|
-
* const
|
|
22
|
-
* const
|
|
23
|
-
* //
|
|
22
|
+
* const negative = D.createTime(-5_000, "millisecond");
|
|
23
|
+
* const short = D.formatTime(negative, "ss.SSS");
|
|
24
|
+
* // short: string
|
|
24
25
|
* ```
|
|
25
26
|
*
|
|
26
27
|
* @remarks
|
|
27
|
-
* -
|
|
28
|
+
* - Supported tokens: `WW`, `DD`, `HH`, `mm`, `ss`, `SSS`.
|
|
28
29
|
*
|
|
29
30
|
* @see https://utils.duplojs.dev/en/v1/api/date/formatTime
|
|
30
31
|
*
|
|
31
32
|
* @namespace D
|
|
32
33
|
*
|
|
33
34
|
*/
|
|
34
|
-
export declare function formatTime<GenericInput extends TheTime, GenericFormat extends string>(formatString: GenericFormat): (input: GenericInput) => string;
|
|
35
|
-
export declare function formatTime<GenericInput extends TheTime, GenericFormat extends string>(input: GenericInput, formatString: GenericFormat): string;
|
|
35
|
+
export declare function formatTime<GenericInput extends TheTime | SerializedTheTime, GenericFormat extends string>(formatString: GenericFormat): (input: GenericInput) => string;
|
|
36
|
+
export declare function formatTime<GenericInput extends TheTime | SerializedTheTime, GenericFormat extends string>(input: GenericInput, formatString: GenericFormat): string;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var theDate = require('./theDate.cjs');
|
|
3
4
|
var toNative = require('./toNative.cjs');
|
|
4
5
|
|
|
5
6
|
function getTimezoneOffset(...args) {
|
|
6
7
|
if (args.length === 1) {
|
|
7
8
|
const [timeZone] = args;
|
|
8
|
-
return (
|
|
9
|
+
return (input) => getTimezoneOffset(input, timeZone);
|
|
9
10
|
}
|
|
10
|
-
const [
|
|
11
|
-
const date =
|
|
11
|
+
const [input, timeZone] = args;
|
|
12
|
+
const date = input instanceof theDate.TheDate
|
|
13
|
+
? input
|
|
14
|
+
: toNative.toNative(input);
|
|
12
15
|
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
13
16
|
timeZone,
|
|
14
17
|
hour12: false,
|
|
@@ -1,33 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { Timezone } from "./timezone";
|
|
2
|
+
import { TheDate } from "./theDate";
|
|
3
|
+
import type { SerializedTheDate } from "./types";
|
|
3
4
|
/**
|
|
4
|
-
* Returns
|
|
5
|
+
* Returns timezone offset in milliseconds for a given date and timezone.
|
|
5
6
|
*
|
|
6
7
|
* **Supported call styles:**
|
|
7
|
-
* - Classic: `getTimezoneOffset(timeZone)` →
|
|
8
|
-
* - Curried: `getTimezoneOffset(
|
|
8
|
+
* - Classic: `getTimezoneOffset(input, timeZone)` → `number`
|
|
9
|
+
* - Curried: `getTimezoneOffset(timeZone)` → `(input) => number`
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
+
* `input` accepts `TheDate` or `SerializedTheDate`.
|
|
11
12
|
*
|
|
12
13
|
* ```ts
|
|
13
|
-
* const
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* const input = D.create("2024-01-01", {
|
|
15
|
+
* hour: "00",
|
|
16
|
+
* });
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* D.getTimezoneOffset("America/New_York"),
|
|
20
|
-
* ); // offset: -18000000
|
|
18
|
+
* const offset = D.getTimezoneOffset(input, "America/New_York");
|
|
19
|
+
* // offset: number
|
|
21
20
|
*
|
|
21
|
+
* pipe(
|
|
22
|
+
* input,
|
|
23
|
+
* D.getTimezoneOffset("Europe/Paris"),
|
|
22
24
|
* ```
|
|
23
25
|
*
|
|
24
|
-
* @remarks
|
|
25
|
-
* - Returns the offset in milliseconds for the given timezone.
|
|
26
|
-
*
|
|
27
26
|
* @see https://utils.duplojs.dev/en/v1/api/date/getTimezoneOffset
|
|
28
27
|
*
|
|
29
28
|
* @namespace D
|
|
30
29
|
*
|
|
31
30
|
*/
|
|
32
|
-
export declare function getTimezoneOffset(timeZone: Timezone): (
|
|
33
|
-
export declare function getTimezoneOffset(
|
|
31
|
+
export declare function getTimezoneOffset(timeZone: Timezone): (input: TheDate | SerializedTheDate) => number;
|
|
32
|
+
export declare function getTimezoneOffset(input: TheDate | SerializedTheDate, timeZone: Timezone): number;
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import { TheDate } from './theDate.mjs';
|
|
1
2
|
import { toNative } from './toNative.mjs';
|
|
2
3
|
|
|
3
4
|
function getTimezoneOffset(...args) {
|
|
4
5
|
if (args.length === 1) {
|
|
5
6
|
const [timeZone] = args;
|
|
6
|
-
return (
|
|
7
|
+
return (input) => getTimezoneOffset(input, timeZone);
|
|
7
8
|
}
|
|
8
|
-
const [
|
|
9
|
-
const date =
|
|
9
|
+
const [input, timeZone] = args;
|
|
10
|
+
const date = input instanceof TheDate
|
|
11
|
+
? input
|
|
12
|
+
: toNative(input);
|
|
10
13
|
const fmt = new Intl.DateTimeFormat("en-US", {
|
|
11
14
|
timeZone,
|
|
12
15
|
hour12: false,
|
|
@@ -6,15 +6,15 @@ var toNative = require('../toNative.cjs');
|
|
|
6
6
|
* {@include date/getDayOfMonth/index.md}
|
|
7
7
|
*/
|
|
8
8
|
function getDayOfMonth(input, timezone = "UTC") {
|
|
9
|
-
const
|
|
9
|
+
const date = toNative.toNative(input);
|
|
10
10
|
if (timezone === "UTC") {
|
|
11
|
-
return
|
|
11
|
+
return date.getUTCDate();
|
|
12
12
|
}
|
|
13
13
|
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
14
14
|
timeZone: timezone,
|
|
15
15
|
day: "numeric",
|
|
16
16
|
});
|
|
17
|
-
return Number(formatter.format(
|
|
17
|
+
return Number(formatter.format(date));
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
exports.getDayOfMonth = getDayOfMonth;
|
|
@@ -1,31 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { SerializedTheDate } from "../types";
|
|
2
|
+
import type { TheDate } from "../theDate";
|
|
3
|
+
import type { Timezone } from "../timezone";
|
|
2
4
|
/**
|
|
3
|
-
* Returns the day of month
|
|
5
|
+
* Returns the day of month (`1` to `31`) for a date in a target timezone.
|
|
4
6
|
*
|
|
5
|
-
* Signature: `getDayOfMonth(input, timezone)` →
|
|
7
|
+
* Signature: `getDayOfMonth(input, timezone?)` → `number`
|
|
6
8
|
*
|
|
7
|
-
* If timezone is omitted, UTC is used.
|
|
8
|
-
*
|
|
9
|
-
* The input value is not mutated.
|
|
9
|
+
* `input` accepts `TheDate` or `SerializedTheDate`. If `timezone` is omitted, UTC is used.
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
|
-
* const input = D.create("2024-06-01"
|
|
13
|
-
*
|
|
14
|
-
*
|
|
12
|
+
* const input = D.create("2024-06-01", {
|
|
13
|
+
* hour: "00",
|
|
14
|
+
* minute: "30",
|
|
15
|
+
* });
|
|
16
|
+
* const utcDay = D.getDayOfMonth(input);
|
|
17
|
+
* // utcDay: 1
|
|
15
18
|
*
|
|
16
|
-
* const
|
|
17
|
-
* //
|
|
19
|
+
* const laDay = D.getDayOfMonth(input, "America/Los_Angeles");
|
|
20
|
+
* // laDay: 31
|
|
18
21
|
*
|
|
19
22
|
* pipe(
|
|
20
23
|
* input,
|
|
21
|
-
* D.getDayOfMonth,
|
|
22
|
-
* ); //
|
|
24
|
+
* (value) => D.getDayOfMonth(value, "UTC"),
|
|
25
|
+
* ); // 1
|
|
23
26
|
*
|
|
24
27
|
* ```
|
|
25
28
|
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - The same instant can map to a different calendar day depending on timezone.
|
|
31
|
+
*
|
|
26
32
|
* @see https://utils.duplojs.dev/en/v1/api/date/getDayOfMonth
|
|
27
33
|
*
|
|
28
34
|
* @namespace D
|
|
29
35
|
*
|
|
30
36
|
*/
|
|
31
|
-
export declare function getDayOfMonth<GenericInput extends TheDate>(input: GenericInput, timezone?: Timezone): number;
|
|
37
|
+
export declare function getDayOfMonth<GenericInput extends TheDate | SerializedTheDate>(input: GenericInput, timezone?: Timezone): number;
|
|
@@ -4,15 +4,15 @@ import { toNative } from '../toNative.mjs';
|
|
|
4
4
|
* {@include date/getDayOfMonth/index.md}
|
|
5
5
|
*/
|
|
6
6
|
function getDayOfMonth(input, timezone = "UTC") {
|
|
7
|
-
const
|
|
7
|
+
const date = toNative(input);
|
|
8
8
|
if (timezone === "UTC") {
|
|
9
|
-
return
|
|
9
|
+
return date.getUTCDate();
|
|
10
10
|
}
|
|
11
11
|
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
12
12
|
timeZone: timezone,
|
|
13
13
|
day: "numeric",
|
|
14
14
|
});
|
|
15
|
-
return Number(formatter.format(
|
|
15
|
+
return Number(formatter.format(date));
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export { getDayOfMonth };
|
|
@@ -15,15 +15,15 @@ const weekdayMapper = {
|
|
|
15
15
|
* {@include date/getDayOfWeek/index.md}
|
|
16
16
|
*/
|
|
17
17
|
function getDayOfWeek(input, timezone = "UTC") {
|
|
18
|
-
const
|
|
18
|
+
const date = toNative.toNative(input);
|
|
19
19
|
if (timezone === "UTC") {
|
|
20
|
-
return
|
|
20
|
+
return date.getUTCDay();
|
|
21
21
|
}
|
|
22
22
|
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
23
23
|
timeZone: timezone,
|
|
24
24
|
weekday: "long",
|
|
25
25
|
});
|
|
26
|
-
const weekday = formatter.format(
|
|
26
|
+
const weekday = formatter.format(date);
|
|
27
27
|
return weekdayMapper[weekday];
|
|
28
28
|
}
|
|
29
29
|
|