@vedanshshetti/zeit 1.1.0-post1 → 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/LICENSE +286 -286
- package/README.md +238 -2
- package/dist/just-a-test.js +1 -1
- package/dist/just-a-test.js.map +1 -1
- package/dist/modules/now.d.ts +1 -1
- package/dist/modules/now.d.ts.map +1 -1
- package/dist/modules/now.js +2 -1
- package/dist/modules/now.js.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +10 -10
- package/src/modules/before.ts +50 -50
- package/src/modules/in.ts +50 -50
- package/src/modules/now.ts +46 -45
- package/src/stuff.ts +37 -37
- package/src/types.ts +16 -16
- package/src/just-a-test.ts +0 -32
package/src/stuff.ts
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
import type { UnitOfTime, Wording } from "./types.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @private
|
|
5
|
-
*/
|
|
6
|
-
export function parseWording(x: Wording) {
|
|
7
|
-
const pieces = x.split(" ") as [string, string];
|
|
8
|
-
if (pieces.length !== 2) {
|
|
9
|
-
throw new Error(`Invalid wording format: "${x}". Expected format: "<number> <unit>"`);
|
|
10
|
-
}
|
|
11
|
-
const value = parseInt(pieces[0], 10);
|
|
12
|
-
if (isNaN(value)) {
|
|
13
|
-
throw new Error(`Invalid number in wording: "${x}"`);
|
|
14
|
-
}
|
|
15
|
-
return {
|
|
16
|
-
value,
|
|
17
|
-
unit: pieces[1] as UnitOfTime
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function toLocalISOString(d: Date): string {
|
|
22
|
-
const pad = (n: number) => String(n).padStart(2, "0");
|
|
23
|
-
|
|
24
|
-
const year = d.getFullYear();
|
|
25
|
-
const month = pad(d.getMonth() + 1);
|
|
26
|
-
const day = pad(d.getDate());
|
|
27
|
-
const hours = pad(d.getHours());
|
|
28
|
-
const minutes = pad(d.getMinutes());
|
|
29
|
-
const seconds = pad(d.getSeconds());
|
|
30
|
-
|
|
31
|
-
// Handle timezone offset
|
|
32
|
-
const offset = -d.getTimezoneOffset();
|
|
33
|
-
const sign = offset >= 0 ? "+" : "-";
|
|
34
|
-
const offsetHours = pad(Math.floor(Math.abs(offset) / 60));
|
|
35
|
-
const offsetMins = pad(Math.abs(offset) % 60);
|
|
36
|
-
|
|
37
|
-
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${sign}${offsetHours}:${offsetMins}`;
|
|
1
|
+
import type { UnitOfTime, Wording } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
export function parseWording(x: Wording) {
|
|
7
|
+
const pieces = x.split(" ") as [string, string];
|
|
8
|
+
if (pieces.length !== 2) {
|
|
9
|
+
throw new Error(`Invalid wording format: "${x}". Expected format: "<number> <unit>"`);
|
|
10
|
+
}
|
|
11
|
+
const value = parseInt(pieces[0], 10);
|
|
12
|
+
if (isNaN(value)) {
|
|
13
|
+
throw new Error(`Invalid number in wording: "${x}"`);
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
value,
|
|
17
|
+
unit: pieces[1] as UnitOfTime
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function toLocalISOString(d: Date): string {
|
|
22
|
+
const pad = (n: number) => String(n).padStart(2, "0");
|
|
23
|
+
|
|
24
|
+
const year = d.getFullYear();
|
|
25
|
+
const month = pad(d.getMonth() + 1);
|
|
26
|
+
const day = pad(d.getDate());
|
|
27
|
+
const hours = pad(d.getHours());
|
|
28
|
+
const minutes = pad(d.getMinutes());
|
|
29
|
+
const seconds = pad(d.getSeconds());
|
|
30
|
+
|
|
31
|
+
// Handle timezone offset
|
|
32
|
+
const offset = -d.getTimezoneOffset();
|
|
33
|
+
const sign = offset >= 0 ? "+" : "-";
|
|
34
|
+
const offsetHours = pad(Math.floor(Math.abs(offset) / 60));
|
|
35
|
+
const offsetMins = pad(Math.abs(offset) % 60);
|
|
36
|
+
|
|
37
|
+
return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}${sign}${offsetHours}:${offsetMins}`;
|
|
38
38
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export type UnitOfTime =
|
|
2
|
-
| "milliseconds"
|
|
3
|
-
| "ms"
|
|
4
|
-
| "seconds"
|
|
5
|
-
| "s"
|
|
6
|
-
| "minutes"
|
|
7
|
-
| "min"
|
|
8
|
-
| "hours"
|
|
9
|
-
| "h"
|
|
10
|
-
| "days"
|
|
11
|
-
| "months"
|
|
12
|
-
| "years"
|
|
13
|
-
| "decades"
|
|
14
|
-
| "centuries"
|
|
15
|
-
| "millennia";
|
|
16
|
-
export type Wording = `${number} ${UnitOfTime}`;
|
|
1
|
+
export type UnitOfTime =
|
|
2
|
+
| "milliseconds"
|
|
3
|
+
| "ms"
|
|
4
|
+
| "seconds"
|
|
5
|
+
| "s"
|
|
6
|
+
| "minutes"
|
|
7
|
+
| "min"
|
|
8
|
+
| "hours"
|
|
9
|
+
| "h"
|
|
10
|
+
| "days"
|
|
11
|
+
| "months"
|
|
12
|
+
| "years"
|
|
13
|
+
| "decades"
|
|
14
|
+
| "centuries"
|
|
15
|
+
| "millennia";
|
|
16
|
+
export type Wording = `${number} ${UnitOfTime}`;
|
package/src/just-a-test.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { zeit } from "./index.js";
|
|
2
|
-
|
|
3
|
-
console.log(
|
|
4
|
-
'zeit.before("5 hours").toString(): ',
|
|
5
|
-
zeit.before("5 hours").toString(),
|
|
6
|
-
);
|
|
7
|
-
console.log('zeit.before("5 hours").toString(): ', zeit.before("5 hours").toString());
|
|
8
|
-
console.log('zeit.in("5 hours").toString(): ', zeit.in("5 hours").toString());
|
|
9
|
-
console.log('zeit.in("5 hours").toString(): ', zeit.in("5 hours").toString());
|
|
10
|
-
|
|
11
|
-
console.log(
|
|
12
|
-
'zeit.now("ISO 8601:1-2019 Extended',
|
|
13
|
-
'Local Time") : ',
|
|
14
|
-
zeit.now("ISO 8601:1-2019 Extended", "Local Time"),
|
|
15
|
-
);
|
|
16
|
-
console.log(
|
|
17
|
-
'zeit.now("ISO 8601:1-2019 Extended") Omitted Timezone: ',
|
|
18
|
-
zeit.now("ISO 8601:1-2019 Extended"),
|
|
19
|
-
);
|
|
20
|
-
console.log(
|
|
21
|
-
'zeit.now("ISO 8601:1-2019 Extended',
|
|
22
|
-
'UTC") : ',
|
|
23
|
-
zeit.now("ISO 8601:1-2019 Extended", "UTC"),
|
|
24
|
-
);
|
|
25
|
-
console.log(
|
|
26
|
-
'zeit.now("Unix Epoch") : ',
|
|
27
|
-
zeit.now("Unix Epoch"),
|
|
28
|
-
);
|
|
29
|
-
console.log(
|
|
30
|
-
'zeit.now("Human Readable") : ',
|
|
31
|
-
zeit.now("Human Readable"),
|
|
32
|
-
);
|