@vedanshshetti/zeit 1.1.0 → 1.2.0

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/README.md CHANGED
@@ -1,2 +1,238 @@
1
- # zeit
2
- A date/time library for JavaScript / TypeScript.
1
+ # zeit
2
+
3
+ A free, typed Date & Time library for JavaScript / TypeScript.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @vedanshshetti/zeit
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Import
14
+
15
+ ```typescript
16
+ import { zeit } from "@vedanshshetti/zeit";
17
+
18
+ // Or for CommonJS
19
+ const { zeit } = require("@vedanshshetti/zeit");
20
+ ```
21
+
22
+ ### Methods
23
+
24
+ The `zeit` object provides three main methods:
25
+
26
+ | Method | Description |
27
+ |--------|-------------|
28
+ | `zeit.now()` | Get the current date/time |
29
+ | `zeit.in()` | Get a future date/time |
30
+ | `zeit.before()` | Get a past date/time |
31
+
32
+ ---
33
+
34
+ ## `zeit.now()`
35
+
36
+ Gets the current date and time in various formats.
37
+
38
+ ### Parameters
39
+
40
+ - **format** (required): One of:
41
+ - `"Unix Epoch"` - Returns milliseconds since Unix epoch
42
+ - `"ISO 8601:1-2019 Extended"` - Returns ISO 8601 formatted string
43
+ - `"Human Readable"` - Returns a human-readable date string
44
+ - **timezone** (optional): `"UTC"` or `"Local Time"` (default: `"Local Time"`)
45
+
46
+ ### Examples
47
+
48
+ ```typescript
49
+ // Get Unix epoch timestamp
50
+ const epoch = zeit.now("Unix Epoch");
51
+ // => 1712345678901
52
+
53
+ // Get ISO 8601 string in local time
54
+ const isoLocal = zeit.now("ISO 8601:1-2019 Extended");
55
+ // => "2024-04-05T14:30:45+05:30"
56
+
57
+ // Get ISO 8601 string in UTC
58
+ const isoUTC = zeit.now("ISO 8601:1-2019 Extended", "UTC");
59
+ // => "2024-04-05T09:00:45.123Z"
60
+
61
+ // Get human-readable format
62
+ const readable = zeit.now("Human Readable");
63
+ // => "5th April 2024, 14:30 (123ms)"
64
+ ```
65
+
66
+ ---
67
+
68
+ ## `zeit.in()`
69
+
70
+ Calculate a future date/time by adding a time duration to the current time.
71
+
72
+ ### Parameters
73
+
74
+ - **words** (required): A string in the format `"<number> <unit>"`
75
+
76
+ ### Supported Units
77
+
78
+ | Unit | Alias | Description |
79
+ |------|-------|-------------|
80
+ | `milliseconds` | `ms` | Milliseconds |
81
+ | `seconds` | `s` | Seconds |
82
+ | `minutes` | `min` | Minutes |
83
+ | `hours` | `h` | Hours |
84
+ | `days` | - | Days |
85
+ | `months` | - | Months |
86
+ | `years` | - | Years |
87
+ | `decades` | - | Decades (10 years) |
88
+ | `centuries` | - | Centuries (100 years) |
89
+ | `millennia` | - | Millennia (1000 years) |
90
+
91
+ ### Examples
92
+
93
+ ```typescript
94
+ // 5 minutes from now
95
+ const inFiveMinutes = zeit.in("5 minutes");
96
+
97
+ // 2 hours from now
98
+ const inTwoHours = zeit.in("2 hours");
99
+ // or
100
+ const inTwoHours = zeit.in("2 h");
101
+
102
+ // 3 days from now
103
+ const inThreeDays = zeit.in("3 days");
104
+
105
+ // 1 decade from now (10 years)
106
+ const inTenYears = zeit.in("1 decades");
107
+
108
+ // 500 milliseconds from now
109
+ const inHalfSecond = zeit.in("500 milliseconds");
110
+ // or
111
+ const inHalfSecond = zeit.in("500 ms");
112
+ ```
113
+
114
+ ### Return Value
115
+
116
+ Returns a `Date` object representing the future date/time.
117
+
118
+ ```typescript
119
+ const futureDate = zeit.in("10 days");
120
+ console.log(futureDate.toISOString());
121
+ // => "2024-04-15T14:30:45.123Z"
122
+ ```
123
+
124
+ ---
125
+
126
+ ## `zeit.before()`
127
+
128
+ Calculate a past date/time by subtracting a time duration from the current time.
129
+
130
+ ### Parameters
131
+
132
+ - **words** (required): A string in the format `"<number> <unit>"`
133
+
134
+ ### Supported Units
135
+
136
+ Same as `zeit.in()` - see the [table above](#supported-units).
137
+
138
+ ### Examples
139
+
140
+ ```typescript
141
+ // 5 minutes ago
142
+ const fiveMinutesAgo = zeit.before("5 minutes");
143
+
144
+ // 2 hours ago
145
+ const twoHoursAgo = zeit.before("2 hours");
146
+ // or
147
+ const twoHoursAgo = zeit.before("2 h");
148
+
149
+ // 3 days ago
150
+ const threeDaysAgo = zeit.before("3 days");
151
+
152
+ // 1 century ago (100 years)
153
+ const hundredYearsAgo = zeit.before("1 centuries");
154
+
155
+ // 250 milliseconds ago
156
+ const quarterSecondAgo = zeit.before("250 ms");
157
+ ```
158
+
159
+ ### Return Value
160
+
161
+ Returns a `Date` object representing the past date/time.
162
+
163
+ ```typescript
164
+ const pastDate = zeit.before("10 days");
165
+ console.log(pastDate.toISOString());
166
+ // => "2024-03-26T14:30:45.123Z"
167
+ ```
168
+
169
+ ---
170
+
171
+ ## Type Safety
172
+
173
+ The library is fully typed with TypeScript:
174
+
175
+ ```typescript
176
+ // All methods are type-safe
177
+ const epoch: number = zeit.now("Unix Epoch");
178
+ const iso: string = zeit.now("ISO 8601:1-2019 Extended");
179
+ const date: Date = zeit.in("5 days");
180
+ const pastDate: Date = zeit.before("2 hours");
181
+
182
+ // Invalid formats are caught at compile time
183
+ // @ts-expect-error - Invalid format
184
+ zeit.now("Invalid Format");
185
+ ```
186
+
187
+ ---
188
+
189
+ ## Use Cases
190
+
191
+ ### Scheduling
192
+
193
+ ```typescript
194
+ const reminderTime = zeit.in("30 minutes");
195
+ setTimeout(() => {
196
+ console.log("Reminder!");
197
+ }, reminderTime.getTime() - Date.now());
198
+ ```
199
+
200
+ ### Time Calculations
201
+
202
+ ```typescript
203
+ const now = new Date();
204
+ const oneWeekAgo = zeit.before("7 days");
205
+ const timeDifference = now.getTime() - oneWeekAgo.getTime();
206
+ ```
207
+
208
+ ### Human-Readable Timestamps
209
+
210
+ ```typescript
211
+ function logWithTimestamp(message: string) {
212
+ const timestamp = zeit.now("Human Readable");
213
+ console.log(`[${timestamp}] ${message}`);
214
+ }
215
+
216
+ logWithTimestamp("Application started");
217
+ // => [5th April 2024, 14:30 (123ms)] Application started
218
+ ```
219
+
220
+ ### Expiration Dates
221
+
222
+ ```typescript
223
+ const sessionExpiry = zeit.in("24 hours");
224
+ const tokenExpiry = zeit.in("1 hours");
225
+ ```
226
+
227
+ ---
228
+
229
+ ## License
230
+
231
+ EUPL-1.2
232
+
233
+ ---
234
+
235
+ ## Repository
236
+
237
+ - [GitHub](https://github.com/vedanshshetti/zeit)
238
+ - [Issues](https://github.com/vedanshshetti/zeit/issues)
@@ -0,0 +1,9 @@
1
+ import before from "./modules/before.js";
2
+ import inX from "./modules/in.js";
3
+ import now from "./modules/now.js";
4
+ export declare const zeit: {
5
+ readonly in: typeof inX;
6
+ readonly before: typeof before;
7
+ readonly now: typeof now;
8
+ };
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AAEnC,eAAO,MAAM,IAAI;;;;CAIP,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import before from "./modules/before.js";
2
+ import inX from "./modules/in.js";
3
+ import now from "./modules/now.js";
4
+ export const zeit = {
5
+ in: inX,
6
+ before,
7
+ now
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,GAAG,MAAM,iBAAiB,CAAC;AAClC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AAEnC,MAAM,CAAC,MAAM,IAAI,GAAG;IAChB,EAAE,EAAE,GAAG;IACP,MAAM;IACN,GAAG;CACG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=just-a-test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"just-a-test.d.ts","sourceRoot":"","sources":["../src/just-a-test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import { zeit } from "./index.js";
2
+ console.log('zeit.before("5 hours").toString(): ', zeit.before("5 hours").toString());
3
+ console.log('zeit.before("5 hours").toString(): ', zeit.before("5 hours").toString());
4
+ console.log('zeit.in("5 hours").toString(): ', zeit.in("5 hours").toString());
5
+ console.log('zeit.in("5 hours").toString(): ', zeit.in("5 hours").toString());
6
+ console.log('zeit.now("ISO 8601:1-2019 Extended', 'Local Time") : ', zeit.now("ISO 8601:1-2019 Extended", "Local Time"));
7
+ console.log('zeit.now("ISO 8601:1-2019 Extended") Omitted Timezone: ', zeit.now("ISO 8601:1-2019 Extended"));
8
+ console.log('zeit.now("ISO 8601:1-2019 Extended', 'UTC") : ', zeit.now("ISO 8601:1-2019 Extended", "UTC"));
9
+ console.log('zeit.now("Unix") : ', zeit.now("Unix"));
10
+ console.log('zeit.now("Human Readable") : ', zeit.now("Human Readable"));
11
+ //# sourceMappingURL=just-a-test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"just-a-test.js","sourceRoot":"","sources":["../src/just-a-test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAElC,OAAO,CAAC,GAAG,CACT,qCAAqC,EACrC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAClC,CAAC;AACF,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACtF,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAC9E,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AAE9E,OAAO,CAAC,GAAG,CACT,oCAAoC,EACpC,iBAAiB,EACjB,IAAI,CAAC,GAAG,CAAC,0BAA0B,EAAE,YAAY,CAAC,CACnD,CAAC;AACF,OAAO,CAAC,GAAG,CACT,yDAAyD,EACzD,IAAI,CAAC,GAAG,CAAC,0BAA0B,CAAC,CACrC,CAAC;AACF,OAAO,CAAC,GAAG,CACT,oCAAoC,EACpC,UAAU,EACV,IAAI,CAAC,GAAG,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAC5C,CAAC;AACF,OAAO,CAAC,GAAG,CACT,qBAAqB,EACrB,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CACjB,CAAC;AACF,OAAO,CAAC,GAAG,CACT,+BAA+B,EAC/B,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAC3B,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Wording } from "../types.js";
2
+ declare const before: (words: Wording) => Date;
3
+ export default before;
4
+ //# sourceMappingURL=before.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"before.d.ts","sourceRoot":"","sources":["../../src/modules/before.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAA,MAAM,MAAM,UAAW,OAAO,SA4C7B,CAAC;eAEa,MAAM"}
@@ -0,0 +1,46 @@
1
+ import { parseWording } from "../stuff.js";
2
+ const before = (words) => {
3
+ const now = new Date();
4
+ const d = now;
5
+ const parsed = parseWording(words);
6
+ let multiplier = 1;
7
+ if (parsed.unit === "decades")
8
+ multiplier = 10;
9
+ else if (parsed.unit === "centuries")
10
+ multiplier = 100;
11
+ else if (parsed.unit === "millennia")
12
+ multiplier = 1000;
13
+ const amount = 0 - parsed.value * multiplier;
14
+ // 3. Use switch with BREAKS
15
+ switch (parsed.unit) {
16
+ case "days":
17
+ d.setDate(d.getDate() + amount);
18
+ break;
19
+ case "h":
20
+ case "hours":
21
+ d.setHours(d.getHours() + amount);
22
+ break;
23
+ case "min":
24
+ case "minutes":
25
+ d.setMinutes(d.getMinutes() + amount);
26
+ break;
27
+ case "s":
28
+ case "seconds":
29
+ d.setSeconds(d.getSeconds() + amount);
30
+ break;
31
+ case "months":
32
+ d.setMonth(d.getMonth() + amount);
33
+ break;
34
+ case "milliseconds":
35
+ case "ms":
36
+ d.setMilliseconds(d.getMilliseconds() + amount);
37
+ break;
38
+ default:
39
+ // Treat unknown units as years
40
+ d.setFullYear(d.getFullYear() + amount);
41
+ break;
42
+ }
43
+ return d;
44
+ };
45
+ export default before;
46
+ //# sourceMappingURL=before.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"before.js","sourceRoot":"","sources":["../../src/modules/before.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,MAAM,GAAG,CAAC,KAAc,EAAE,EAAE;IAChC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,GAAG,CAAC;IAEd,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAEnC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,UAAU,GAAG,EAAE,CAAC;SAC1C,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,UAAU,GAAG,GAAG,CAAC;SAClD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,UAAU,GAAG,IAAI,CAAC;IAExD,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC;IAE7C,4BAA4B;IAC5B,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,MAAM;YACT,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;YAChC,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,OAAO;YACV,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;YAClC,MAAM;QACR,KAAK,KAAK,CAAC;QACX,KAAK,SAAS;YACZ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC;YACtC,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,SAAS;YACZ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC;YACtC,MAAM;QACR,KAAK,QAAQ;YACX,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;YAClC,MAAM;QACR,KAAK,cAAc,CAAC;QACpB,KAAK,IAAI;YACP,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,EAAE,GAAG,MAAM,CAAC,CAAC;YAChD,MAAM;QACR;YACE,+BAA+B;YAC/B,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,CAAC;YACxC,MAAM;IACV,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Wording } from "../types.js";
2
+ declare const inX: (words: Wording) => Date;
3
+ export default inX;
4
+ //# sourceMappingURL=in.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in.d.ts","sourceRoot":"","sources":["../../src/modules/in.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,QAAA,MAAM,GAAG,UAAW,OAAO,SA4C1B,CAAC;eAEa,GAAG"}
@@ -0,0 +1,46 @@
1
+ import { parseWording } from "../stuff.js";
2
+ const inX = (words) => {
3
+ const now = new Date();
4
+ const d = now;
5
+ const parsed = parseWording(words);
6
+ let multiplier = 1;
7
+ if (parsed.unit === "decades")
8
+ multiplier = 10;
9
+ else if (parsed.unit === "centuries")
10
+ multiplier = 100;
11
+ else if (parsed.unit === "millennia")
12
+ multiplier = 1000;
13
+ const amount = parsed.value * multiplier;
14
+ // 3. Use switch with BREAKS
15
+ switch (parsed.unit) {
16
+ case "days":
17
+ d.setDate(d.getDate() + amount);
18
+ break;
19
+ case "h":
20
+ case "hours":
21
+ d.setHours(d.getHours() + amount);
22
+ break;
23
+ case "min":
24
+ case "minutes":
25
+ d.setMinutes(d.getMinutes() + amount);
26
+ break;
27
+ case "s":
28
+ case "seconds":
29
+ d.setSeconds(d.getSeconds() + amount);
30
+ break;
31
+ case "months":
32
+ d.setMonth(d.getMonth() + amount);
33
+ break;
34
+ case "milliseconds":
35
+ case "ms":
36
+ d.setMilliseconds(d.getMilliseconds() + amount);
37
+ break;
38
+ default:
39
+ // Treat unknown units as years
40
+ d.setFullYear(d.getFullYear() + amount);
41
+ break;
42
+ }
43
+ return d;
44
+ };
45
+ export default inX;
46
+ //# sourceMappingURL=in.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in.js","sourceRoot":"","sources":["../../src/modules/in.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,GAAG,GAAG,CAAC,KAAc,EAAE,EAAE;IAC7B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,CAAC,GAAG,GAAG,CAAC;IAEd,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IAEnC,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS;QAAE,UAAU,GAAG,EAAE,CAAC;SAC1C,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,UAAU,GAAG,GAAG,CAAC;SAClD,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW;QAAE,UAAU,GAAG,IAAI,CAAC;IAExD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC;IAEzC,4BAA4B;IAC5B,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACpB,KAAK,MAAM;YACT,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC;YAChC,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,OAAO;YACV,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;YAClC,MAAM;QACR,KAAK,KAAK,CAAC;QACX,KAAK,SAAS;YACZ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC;YACtC,MAAM;QACR,KAAK,GAAG,CAAC;QACT,KAAK,SAAS;YACZ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,CAAC;YACtC,MAAM;QACR,KAAK,QAAQ;YACX,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;YAClC,MAAM;QACR,KAAK,cAAc,CAAC;QACpB,KAAK,IAAI;YACP,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,eAAe,EAAE,GAAG,MAAM,CAAC,CAAC;YAChD,MAAM;QACR;YACE,+BAA+B;YAC/B,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,MAAM,CAAC,CAAC;YACxC,MAAM;IACV,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC,CAAC;AAEF,eAAe,GAAG,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function now(format: "Unix" | "ISO 8601:1-2019 Extended" | "Human Readable", timezone?: "UTC" | "Local Time"): string | number;
2
+ //# sourceMappingURL=now.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"now.d.ts","sourceRoot":"","sources":["../../src/modules/now.ts"],"names":[],"mappings":"AA0BA,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,MAAM,EAAE,MAAM,GAAG,0BAA0B,GAAG,gBAAgB,EAC9D,QAAQ,GAAE,KAAK,GAAG,YAAyB,mBAiB5C"}
@@ -0,0 +1,36 @@
1
+ import { toLocalISOString } from "../stuff.js";
2
+ const monthsMap = {
3
+ "1": "January",
4
+ "2": "February",
5
+ "3": "March",
6
+ "4": "April",
7
+ "5": "May",
8
+ "6": "June",
9
+ "7": "July",
10
+ "8": "August",
11
+ "9": "September",
12
+ "10": "October",
13
+ "11": "November",
14
+ "12": "December",
15
+ };
16
+ // AI Generated, I have no idea what this is but it works.
17
+ const getOrdinal = (n) => {
18
+ const s = ["th", "st", "nd", "rd"];
19
+ const v = n % 100;
20
+ return s[(v - 20) % 10] || s[v] || "th";
21
+ };
22
+ export default function now(format, timezone = "Local Time") {
23
+ const isLocal = timezone == "Local Time";
24
+ const d = timezone === "Local Time" ? new Date() : new Date(new Date().toUTCString());
25
+ switch (format) {
26
+ case "ISO 8601:1-2019 Extended":
27
+ return isLocal ? toLocalISOString(d) : d.toISOString();
28
+ case "Unix":
29
+ return Date.now();
30
+ case "Human Readable":
31
+ return `${d.getDate()}${getOrdinal(d.getDate())} ${isLocal
32
+ ? monthsMap[(d.getMonth() + 1)]
33
+ : monthsMap[(d.getUTCMonth() + 1)]} ${d.getFullYear()}, ${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")} (${d.getMilliseconds()}ms)`;
34
+ }
35
+ }
36
+ //# sourceMappingURL=now.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"now.js","sourceRoot":"","sources":["../../src/modules/now.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI/C,MAAM,SAAS,GAAgC;IAC7C,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,UAAU;IACf,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;CACR,CAAC;AAEX,0DAA0D;AAC1D,MAAM,UAAU,GAAG,CAAC,CAAS,EAAE,EAAE;IAC/B,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;IAClB,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,GAAG,CACzB,MAA8D,EAC9D,QAAQ,GAAuB,YAAY;IAE3C,MAAM,OAAO,GAAG,QAAQ,IAAI,YAAY,CAAC;IACzC,MAAM,CAAC,GACL,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IAC9E,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,0BAA0B;YAC7B,OAAO,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACzD,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC;QACpB,KAAK,gBAAgB;YACnB,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,IAC7C,OAAO;gBACL,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAgB,CAAC;gBAC9C,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAgB,CACpD,IAAI,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,eAAe,EAAE,KAAK,CAAC;IAChJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { UnitOfTime, Wording } from "./types.js";
2
+ /**
3
+ * @private
4
+ */
5
+ export declare function parseWording(x: Wording): {
6
+ value: number;
7
+ unit: UnitOfTime;
8
+ };
9
+ export declare function toLocalISOString(d: Date): string;
10
+ //# sourceMappingURL=stuff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stuff.d.ts","sourceRoot":"","sources":["../src/stuff.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO;;UAWhB,UAAU;EAEhC;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAiBhD"}
package/dist/stuff.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @private
3
+ */
4
+ export function parseWording(x) {
5
+ const pieces = x.split(" ");
6
+ if (pieces.length !== 2) {
7
+ throw new Error(`Invalid wording format: "${x}". Expected format: "<number> <unit>"`);
8
+ }
9
+ const value = parseInt(pieces[0], 10);
10
+ if (isNaN(value)) {
11
+ throw new Error(`Invalid number in wording: "${x}"`);
12
+ }
13
+ return {
14
+ value,
15
+ unit: pieces[1]
16
+ };
17
+ }
18
+ export function toLocalISOString(d) {
19
+ const pad = (n) => String(n).padStart(2, "0");
20
+ const year = d.getFullYear();
21
+ const month = pad(d.getMonth() + 1);
22
+ const day = pad(d.getDate());
23
+ const hours = pad(d.getHours());
24
+ const minutes = pad(d.getMinutes());
25
+ const seconds = pad(d.getSeconds());
26
+ // Handle timezone offset
27
+ const offset = -d.getTimezoneOffset();
28
+ const sign = offset >= 0 ? "+" : "-";
29
+ const offsetHours = pad(Math.floor(Math.abs(offset) / 60));
30
+ const offsetMins = pad(Math.abs(offset) % 60);
31
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${sign}${offsetHours}:${offsetMins}`;
32
+ }
33
+ //# sourceMappingURL=stuff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stuff.js","sourceRoot":"","sources":["../src/stuff.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,CAAU;IACrC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAqB,CAAC;IAChD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,uCAAuC,CAAC,CAAC;IACxF,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACtC,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,GAAG,CAAC,CAAC;IACvD,CAAC;IACD,OAAO;QACL,KAAK;QACL,IAAI,EAAE,MAAM,CAAC,CAAC,CAAe;KAC9B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAO;IACtC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEtD,MAAM,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC;IACpC,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC7B,MAAM,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;IAEpC,yBAAyB;IACzB,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IACrC,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IAE9C,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,OAAO,IAAI,OAAO,GAAG,IAAI,GAAG,WAAW,IAAI,UAAU,EAAE,CAAC;AACrG,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type UnitOfTime = "milliseconds" | "ms" | "seconds" | "s" | "minutes" | "min" | "hours" | "h" | "days" | "months" | "years" | "decades" | "centuries" | "millennia";
2
+ export type Wording = `${number} ${UnitOfTime}`;
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB,cAAc,GACd,IAAI,GACJ,SAAS,GACT,GAAG,GACH,SAAS,GACT,KAAK,GACL,OAAO,GACP,GAAG,GACH,MAAM,GACN,QAAQ,GACR,OAAO,GACP,SAAS,GACT,WAAW,GACX,WAAW,CAAC;AAChB,MAAM,MAAM,OAAO,GAAG,GAAG,MAAM,IAAI,UAAU,EAAE,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vedanshshetti/zeit",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "A free, typed Date & Time library",
5
5
  "keywords": [
6
6
  "zeit"
@@ -18,12 +18,11 @@
18
18
  "type": "module",
19
19
  "main": "dist/index.js",
20
20
  "scripts": {
21
- "test": "echo \"Error: no test specified\" && exit 1"
21
+ "test": "echo \"Error: no test specified\" && exit 1",
22
+ "prepublishOnly": "tsc"
22
23
  },
23
24
  "devDependencies": {
24
- "@types/node": "^26.6.6"
25
- },
26
- "dependencies": {
25
+ "@types/node": "^26.6.6",
27
26
  "typescript": "^7.0.2"
28
27
  }
29
28
  }
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
- import before from "./modules/before.js";
2
- import inX from "./modules/in.js";
3
- import now from "./modules/now.js";
4
-
5
- export const zeit = {
6
- in: inX,
7
- before,
8
- now
9
- } as const;
10
-
1
+ import before from "./modules/before.js";
2
+ import inX from "./modules/in.js";
3
+ import now from "./modules/now.js";
4
+
5
+ export const zeit = {
6
+ in: inX,
7
+ before,
8
+ now
9
+ } as const;
10
+