@dereekb/date 13.6.11 → 13.6.13

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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@dereekb/date",
3
- "version": "13.6.11",
3
+ "version": "13.6.13",
4
4
  "peerDependencies": {
5
- "@dereekb/model": "13.6.11",
6
- "@dereekb/rxjs": "13.6.11",
7
- "@dereekb/util": "13.6.11",
5
+ "@dereekb/model": "13.6.13",
6
+ "@dereekb/rxjs": "13.6.13",
7
+ "@dereekb/util": "13.6.13",
8
8
  "@vvo/tzdb": "^6.0.0",
9
9
  "arktype": "^2.2.0",
10
10
  "date-fns": "^4.0.0",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "dependencies": {},
16
16
  "devDependencies": {
17
- "@dereekb/rxjs": "13.6.11"
17
+ "@dereekb/rxjs": "13.6.13"
18
18
  },
19
19
  "exports": {
20
20
  "./package.json": "./package.json",
@@ -0,0 +1,140 @@
1
+ import { type Milliseconds, type TimeUnit } from '@dereekb/util';
2
+ /**
3
+ * Represents a time duration decomposed into individual unit fields.
4
+ *
5
+ * Each field is optional and defaults to 0 if not provided.
6
+ * Used for parsing, formatting, and popover picker state.
7
+ */
8
+ export interface TimeDurationData {
9
+ readonly weeks?: number;
10
+ readonly days?: number;
11
+ readonly hours?: number;
12
+ readonly minutes?: number;
13
+ readonly seconds?: number;
14
+ readonly milliseconds?: number;
15
+ }
16
+ /**
17
+ * Returns true if the input TimeDurationData has no meaningful values (all zero or undefined).
18
+ *
19
+ * @param data - The duration data to check
20
+ * @returns True if empty
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * timeDurationDataIsEmpty({}); // true
25
+ * timeDurationDataIsEmpty({ hours: 0, minutes: 0 }); // true
26
+ * timeDurationDataIsEmpty({ hours: 1 }); // false
27
+ * ```
28
+ */
29
+ export declare function timeDurationDataIsEmpty(data: TimeDurationData): boolean;
30
+ /**
31
+ * Converts a TimeDurationData to total milliseconds by summing all fields.
32
+ *
33
+ * @param data - The duration data to convert
34
+ * @returns Total milliseconds
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * durationDataToMilliseconds({ hours: 1, minutes: 30 }); // 5400000
39
+ * durationDataToMilliseconds({ days: 1, hours: 2 }); // 93600000
40
+ * ```
41
+ */
42
+ export declare function durationDataToMilliseconds(data: TimeDurationData): Milliseconds;
43
+ /**
44
+ * Decomposes milliseconds into a TimeDurationData object using the specified units.
45
+ *
46
+ * Breaks down from largest to smallest unit, only using units in the provided list.
47
+ *
48
+ * @param ms - The total milliseconds to decompose
49
+ * @param units - Which units to decompose into (defaults to days, hours, minutes, seconds)
50
+ * @returns A TimeDurationData with the decomposed values
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * millisecondsToDurationData(5400000); // { days: 0, hours: 1, minutes: 30, seconds: 0 }
55
+ * millisecondsToDurationData(90000, ['min', 's']); // { minutes: 1, seconds: 30 }
56
+ * ```
57
+ */
58
+ export declare function millisecondsToDurationData(ms: Milliseconds, units?: readonly TimeUnit[]): TimeDurationData;
59
+ /**
60
+ * Reads a specific time unit value from a TimeDurationData object.
61
+ *
62
+ * @param data - The duration data
63
+ * @param unit - The time unit to read
64
+ * @returns The value for that unit, or 0 if not set
65
+ */
66
+ export declare function getDurationDataValue(data: TimeDurationData, unit: TimeUnit): number;
67
+ /**
68
+ * Returns a new TimeDurationData with the specified unit set to the given value.
69
+ *
70
+ * @param data - The original duration data
71
+ * @param unit - The time unit to set
72
+ * @param value - The new value
73
+ * @returns A new TimeDurationData with the updated value
74
+ */
75
+ export declare function setDurationDataValue(data: TimeDurationData, unit: TimeUnit, value: number): TimeDurationData;
76
+ /**
77
+ * Parses a human-readable duration string into a TimeDurationData object.
78
+ *
79
+ * Supports compact formats ("3d10h5m8s"), spaced formats ("3d 10h 5m 8s"),
80
+ * and long formats ("3 days 10 hours 5 minutes 8 seconds"). Mixed formats
81
+ * are also supported. If the same unit appears multiple times, values are summed.
82
+ *
83
+ * If the string contains only a number with no unit, it is treated as the
84
+ * smallest unit that would make sense (milliseconds by default).
85
+ *
86
+ * @param input - The duration string to parse
87
+ * @returns A TimeDurationData object with the parsed values
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * parseDurationString('3d10h5m8s'); // { days: 3, hours: 10, minutes: 5, seconds: 8 }
92
+ * parseDurationString('2 hours 30 minutes'); // { hours: 2, minutes: 30 }
93
+ * parseDurationString('1w 2d'); // { weeks: 1, days: 2 }
94
+ * parseDurationString('500ms'); // { milliseconds: 500 }
95
+ * ```
96
+ */
97
+ export declare function parseDurationString(input: string): TimeDurationData;
98
+ /**
99
+ * Parses a duration string directly to milliseconds.
100
+ *
101
+ * @param input - The duration string to parse
102
+ * @returns Total milliseconds
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * parseDurationStringToMilliseconds('1h30m'); // 5400000
107
+ * ```
108
+ */
109
+ export declare function parseDurationStringToMilliseconds(input: string): Milliseconds;
110
+ /**
111
+ * Formats a TimeDurationData to a compact string like "3d10h5m8s".
112
+ *
113
+ * Omits zero-value units. Returns "0s" if all fields are zero or empty.
114
+ *
115
+ * @param data - The duration data to format
116
+ * @returns A compact duration string
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * formatDurationString({ days: 3, hours: 10, minutes: 5, seconds: 8 }); // "3d10h5m8s"
121
+ * formatDurationString({ hours: 2, minutes: 30 }); // "2h30m"
122
+ * formatDurationString({}); // "0s"
123
+ * ```
124
+ */
125
+ export declare function formatDurationString(data: TimeDurationData): string;
126
+ /**
127
+ * Formats a TimeDurationData to a long human-readable string.
128
+ *
129
+ * Omits zero-value units. Returns "0 seconds" if all fields are zero or empty.
130
+ *
131
+ * @param data - The duration data to format
132
+ * @returns A human-readable duration string
133
+ *
134
+ * @example
135
+ * ```typescript
136
+ * formatDurationStringLong({ days: 3, hours: 10 }); // "3 days 10 hours"
137
+ * formatDurationStringLong({ hours: 1, minutes: 1 }); // "1 hour 1 minute"
138
+ * ```
139
+ */
140
+ export declare function formatDurationStringLong(data: TimeDurationData): string;
@@ -45,7 +45,7 @@ export declare const dateRangeType: import("arktype/internal/variants/object.ts"
45
45
  export declare const dateRangeParamsType: import("arktype/internal/variants/object.ts").ObjectType<{
46
46
  type: DateRangeType;
47
47
  date: Date | ((In: string) => import("arktype/internal/attributes.ts").To<Date>);
48
- distance?: number | undefined;
48
+ distance?: number | null | undefined;
49
49
  }, {}>;
50
50
  /**
51
51
  * ArkType DTO schema for {@link DateCell}.
@@ -66,7 +66,7 @@ export declare const dateCellType: import("arktype/internal/variants/object.ts")
66
66
  */
67
67
  export declare const dateCellRangeType: import("arktype/internal/variants/object.ts").ObjectType<{
68
68
  i: number;
69
- to?: number | undefined;
69
+ to?: number | null | undefined;
70
70
  }, {}>;
71
71
  /**
72
72
  * ArkType DTO schema for {@link DateCellTiming}.
@@ -102,8 +102,8 @@ export declare const calendarDateType: import("arktype/internal/variants/object.
102
102
  */
103
103
  export declare const dateCellScheduleType: import("arktype/internal/variants/object.ts").ObjectType<{
104
104
  w: string;
105
- d?: number[] | undefined;
106
- ex?: number[] | undefined;
105
+ d?: number[] | null | undefined;
106
+ ex?: number[] | null | undefined;
107
107
  }, {}>;
108
108
  /**
109
109
  * ArkType DTO schema for {@link ModelRecurrenceInfo}.
@@ -116,8 +116,8 @@ export declare const modelRecurrenceInfoType: import("arktype/internal/variants/
116
116
  rrule: string;
117
117
  start: Date | ((In: string) => import("arktype/internal/attributes.ts").To<Date>);
118
118
  end: Date | ((In: string) => import("arktype/internal/attributes.ts").To<Date>);
119
- timezone?: string | undefined;
120
- forever?: boolean | undefined;
119
+ timezone?: string | null | undefined;
120
+ forever?: boolean | null | undefined;
121
121
  }, {}>;
122
122
  /**
123
123
  * ArkType DTO schema that validates a value is a valid {@link DateCellTiming}.
@@ -138,7 +138,7 @@ export declare const validDateCellTimingType: import("arktype/internal/variants/
138
138
  */
139
139
  export declare const validDateCellRangeType: import("arktype/internal/variants/object.ts").ObjectType<{
140
140
  i: number;
141
- to?: number | undefined;
141
+ to?: number | null | undefined;
142
142
  }, {}>;
143
143
  /**
144
144
  * ArkType DTO schema that validates a value is a sorted array of non-overlapping {@link DateCellRange} values.
@@ -147,5 +147,5 @@ export declare const validDateCellRangeType: import("arktype/internal/variants/o
147
147
  */
148
148
  export declare const validDateCellRangeSeriesType: import("arktype/internal/variants/array.ts").ArrayType<{
149
149
  i: number;
150
- to?: number | undefined;
150
+ to?: number | null | undefined;
151
151
  }[], {}>;
@@ -7,6 +7,7 @@ export * from './date.cell';
7
7
  export * from './date.cell.week';
8
8
  export * from './date.calendar';
9
9
  export * from './date.duration';
10
+ export * from './date.duration.data';
10
11
  export * from './date.format';
11
12
  export * from './date.model';
12
13
  export * from './date.hashset';