workclock 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +28 -0
- package/README.md +84 -2
- package/bundler.d.ts +2 -0
- package/bundler.js +2 -0
- package/errors.d.ts +36 -0
- package/errors.js +46 -0
- package/node.d.ts +2 -0
- package/node.js +2 -0
- package/package.json +86 -4
- package/pkg/bundler/package.json +22 -0
- package/pkg/bundler/workclock.d.ts +209 -0
- package/pkg/bundler/workclock.js +9 -0
- package/pkg/bundler/workclock_bg.js +553 -0
- package/pkg/bundler/workclock_bg.wasm +0 -0
- package/pkg/bundler/workclock_bg.wasm.d.ts +22 -0
- package/pkg/node/package.json +16 -0
- package/pkg/node/workclock.d.ts +209 -0
- package/pkg/node/workclock.js +560 -0
- package/pkg/node/workclock_bg.wasm +0 -0
- package/pkg/node/workclock_bg.wasm.d.ts +22 -0
- package/pkg/web/package.json +20 -0
- package/pkg/web/workclock.d.ts +256 -0
- package/pkg/web/workclock.js +658 -0
- package/pkg/web/workclock_bg.wasm +0 -0
- package/pkg/web/workclock_bg.wasm.d.ts +22 -0
- package/web.d.ts +3 -0
- package/web.js +3 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/** A day of the week. */
|
|
5
|
+
export type Weekday = "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Working hours (`"workday"`) or time off within them (`"break"`) on some days
|
|
9
|
+
* of the week. Times are wall-clock times in the rule's time zone, written
|
|
10
|
+
* `HH:MM`, `HH:MM:SS` or `HH:MM:SS.fff` on a 24-hour clock, such as `"09:00"`
|
|
11
|
+
* or `"17:30:00"`.
|
|
12
|
+
*/
|
|
13
|
+
export interface HoursRule {
|
|
14
|
+
type: "workday" | "break";
|
|
15
|
+
/** Wall-clock start, such as `"09:00"`. */
|
|
16
|
+
start: string;
|
|
17
|
+
/** Wall-clock end; at or before `start` means the hours end the next day. */
|
|
18
|
+
end: string;
|
|
19
|
+
/**
|
|
20
|
+
* Days on which the hours start. Defaults to Monday to Friday, for breaks
|
|
21
|
+
* too, so a break on a weekend workday needs its own `days`.
|
|
22
|
+
*/
|
|
23
|
+
days?: readonly Weekday[];
|
|
24
|
+
/** IANA time zone; defaults to the schedule's. */
|
|
25
|
+
timeZone?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Dates that are not worked, each from 00:00 to the next 00:00. */
|
|
29
|
+
export interface HolidaysRule {
|
|
30
|
+
type: "holidays";
|
|
31
|
+
/** Dates such as `"2026-12-25"`. */
|
|
32
|
+
dates: readonly string[];
|
|
33
|
+
/** IANA time zone; defaults to the schedule's. */
|
|
34
|
+
timeZone?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* One rule of a schedule. Working time is the time inside workdays and
|
|
39
|
+
* outside breaks and holidays.
|
|
40
|
+
*/
|
|
41
|
+
export type Rule = HoursRule | HolidaysRule;
|
|
42
|
+
|
|
43
|
+
/** What `new Schedule` takes. */
|
|
44
|
+
export interface ScheduleOptions {
|
|
45
|
+
/** IANA time zone for rules without their own; defaults to `"UTC"`. */
|
|
46
|
+
timeZone?: string;
|
|
47
|
+
/** The rules, in any order. */
|
|
48
|
+
rules: readonly Rule[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A `Date`, or an ISO 8601 string with a UTC offset. */
|
|
52
|
+
export type Instant = Date | string;
|
|
53
|
+
|
|
54
|
+
/** A period: a maximal stretch of working time. */
|
|
55
|
+
export interface Period {
|
|
56
|
+
start: Date;
|
|
57
|
+
end: Date;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Batch methods. Instants come as an array of `Instant`s, returning numbers or
|
|
62
|
+
* `Date`s, or as a `Float64Array` of milliseconds since the epoch, returning a
|
|
63
|
+
* `Float64Array`. Durations come as one number for every item, or one per item.
|
|
64
|
+
* A failing item throws, naming its index.
|
|
65
|
+
*/
|
|
66
|
+
export interface Schedule {
|
|
67
|
+
/**
|
|
68
|
+
* `between` for each pair.
|
|
69
|
+
* @throws {RangeError} If `a` and `b` differ in length.
|
|
70
|
+
*/
|
|
71
|
+
betweenMany(a: Float64Array, b: Float64Array): Float64Array;
|
|
72
|
+
betweenMany(a: readonly Instant[], b: readonly Instant[]): number[];
|
|
73
|
+
betweenMany(a: Float64Array | readonly Instant[], b: Float64Array | readonly Instant[]): Float64Array | number[];
|
|
74
|
+
/** `add` for each instant. */
|
|
75
|
+
addMany(t: Float64Array, ms: number | readonly number[] | Float64Array): Float64Array;
|
|
76
|
+
addMany(t: readonly Instant[], ms: number | readonly number[] | Float64Array): Date[];
|
|
77
|
+
addMany(t: Float64Array | readonly Instant[], ms: number | readonly number[] | Float64Array): Float64Array | Date[];
|
|
78
|
+
/** `sub` for each instant. */
|
|
79
|
+
subMany(t: Float64Array, ms: number | readonly number[] | Float64Array): Float64Array;
|
|
80
|
+
subMany(t: readonly Instant[], ms: number | readonly number[] | Float64Array): Date[];
|
|
81
|
+
subMany(t: Float64Array | readonly Instant[], ms: number | readonly number[] | Float64Array): Float64Array | Date[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Working time defined by rules, evaluated in IANA time zones.
|
|
88
|
+
*
|
|
89
|
+
* Instants are `Date`s or ISO 8601 strings with a UTC offset, and durations
|
|
90
|
+
* are numbers of milliseconds. Results are exact to the millisecond.
|
|
91
|
+
*/
|
|
92
|
+
export class Schedule {
|
|
93
|
+
free(): void;
|
|
94
|
+
[Symbol.dispose](): void;
|
|
95
|
+
/**
|
|
96
|
+
* Finds the instant a given amount of working time after another.
|
|
97
|
+
*
|
|
98
|
+
* @param t The instant to count from.
|
|
99
|
+
* @param ms Working time in milliseconds; a negative amount counts back.
|
|
100
|
+
* @returns The earliest instant with `ms` of working time after `t`, or
|
|
101
|
+
* `t` itself when `ms` is zero.
|
|
102
|
+
* @throws {NoWorkingTimeError} If no working time is found within 366
|
|
103
|
+
* days, plus seven days per holiday date.
|
|
104
|
+
* @throws {OutOfRangeError} If `t` or the result is outside the supported
|
|
105
|
+
* range.
|
|
106
|
+
* @throws {TypeError} If `t` is neither a `Date` nor a string, or `ms` is
|
|
107
|
+
* not a number.
|
|
108
|
+
* @throws {RangeError} If `t` is malformed, or `ms` is not a whole number
|
|
109
|
+
* within ±`Number.MAX_SAFE_INTEGER`.
|
|
110
|
+
* @example
|
|
111
|
+
* ```js
|
|
112
|
+
* const due = support.add("2026-12-24T16:30:00Z", 8 * 3_600_000);
|
|
113
|
+
* due.toISOString(); // "2026-12-30T09:30:00.000Z"
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
add(t: Instant, ms: number): Date;
|
|
117
|
+
/**
|
|
118
|
+
* Measures the working time between two instants.
|
|
119
|
+
*
|
|
120
|
+
* @param a The start.
|
|
121
|
+
* @param b The end.
|
|
122
|
+
* @returns The working time in milliseconds; negative when `b` is before
|
|
123
|
+
* `a`.
|
|
124
|
+
* @throws {OutOfRangeError} If an instant is outside the supported range.
|
|
125
|
+
* @throws {TypeError} If an instant is neither a `Date` nor a string.
|
|
126
|
+
* @throws {RangeError} If an instant is an invalid `Date` or a string
|
|
127
|
+
* without a UTC offset.
|
|
128
|
+
* @example
|
|
129
|
+
* ```js
|
|
130
|
+
* support.between("2026-01-05T09:00:00Z", "2026-01-06T09:00:00Z"); // 25200000, 7 hours
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
between(a: Instant, b: Instant): number;
|
|
134
|
+
/**
|
|
135
|
+
* Builds a schedule from its rules.
|
|
136
|
+
*
|
|
137
|
+
* @param options The default time zone and the rules.
|
|
138
|
+
* @throws {UnknownZoneError} If a time zone is not in the IANA database.
|
|
139
|
+
* @throws {NoWorkingTimeError} If the working hours minus the breaks are
|
|
140
|
+
* empty.
|
|
141
|
+
* @throws {TypeError} If `options` or a rule has the wrong shape; the
|
|
142
|
+
* message names the rule, such as `rules[1]`.
|
|
143
|
+
* @throws {RangeError} If a time, day or date cannot be read.
|
|
144
|
+
* @example
|
|
145
|
+
* ```js
|
|
146
|
+
* const support = new Schedule({
|
|
147
|
+
* timeZone: "Europe/London",
|
|
148
|
+
* rules: [
|
|
149
|
+
* { type: "workday", start: "09:00", end: "17:00" },
|
|
150
|
+
* { type: "break", start: "12:00", end: "13:00" },
|
|
151
|
+
* { type: "holidays", dates: ["2026-12-25", "2026-12-28"] },
|
|
152
|
+
* ],
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
constructor(options: ScheduleOptions);
|
|
157
|
+
/**
|
|
158
|
+
* Finds the period of working time at or after an instant.
|
|
159
|
+
*
|
|
160
|
+
* @param t The instant to search from.
|
|
161
|
+
* @returns The period that contains `t`, starting at `t`, or else the
|
|
162
|
+
* first one after it.
|
|
163
|
+
* @throws {NoWorkingTimeError} If no working time is found within 366
|
|
164
|
+
* days, plus seven days per holiday date.
|
|
165
|
+
* @throws {OutOfRangeError} If `t` is outside the supported range, or the
|
|
166
|
+
* search reaches its end.
|
|
167
|
+
* @throws {TypeError} If `t` is neither a `Date` nor a string.
|
|
168
|
+
* @throws {RangeError} If `t` is malformed.
|
|
169
|
+
*/
|
|
170
|
+
nextPeriod(t: Instant): Period;
|
|
171
|
+
/**
|
|
172
|
+
* Finds the period of working time at or before an instant.
|
|
173
|
+
*
|
|
174
|
+
* @param t The instant to search back from.
|
|
175
|
+
* @returns The period that contains `t`, ending at `t`, or else the last
|
|
176
|
+
* one before it.
|
|
177
|
+
* @throws {NoWorkingTimeError} If no working time is found within 366
|
|
178
|
+
* days, plus seven days per holiday date.
|
|
179
|
+
* @throws {OutOfRangeError} If `t` is outside the supported range, or the
|
|
180
|
+
* search reaches its start.
|
|
181
|
+
* @throws {TypeError} If `t` is neither a `Date` nor a string.
|
|
182
|
+
* @throws {RangeError} If `t` is malformed.
|
|
183
|
+
*/
|
|
184
|
+
previousPeriod(t: Instant): Period;
|
|
185
|
+
/**
|
|
186
|
+
* Finds the instant a given amount of working time before another.
|
|
187
|
+
*
|
|
188
|
+
* @param t The instant to count back from.
|
|
189
|
+
* @param ms Working time in milliseconds; a negative amount counts
|
|
190
|
+
* forward.
|
|
191
|
+
* @returns The latest instant with `ms` of working time before `t`, or
|
|
192
|
+
* `t` itself when `ms` is zero.
|
|
193
|
+
* @throws {NoWorkingTimeError} If no working time is found within 366
|
|
194
|
+
* days, plus seven days per holiday date.
|
|
195
|
+
* @throws {OutOfRangeError} If `t` or the result is outside the supported
|
|
196
|
+
* range.
|
|
197
|
+
* @throws {TypeError} If `t` is neither a `Date` nor a string, or `ms` is
|
|
198
|
+
* not a number.
|
|
199
|
+
* @throws {RangeError} If `t` is malformed, or `ms` is not a whole number
|
|
200
|
+
* within ±`Number.MAX_SAFE_INTEGER`.
|
|
201
|
+
*/
|
|
202
|
+
sub(t: Instant, ms: number): Date;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Returns the version of workclock this module was built from, such as
|
|
207
|
+
* `"0.1.0"`.
|
|
208
|
+
*/
|
|
209
|
+
export function version(): string;
|