@sapphire/timestamp 1.0.1-next.574299a.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/CHANGELOG.md +0 -0
- package/README.md +119 -0
- package/dist/index.d.ts +102 -0
- package/dist/index.global.js +240 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +247 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +217 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +68 -0
package/CHANGELOG.md
ADDED
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
# @sapphire/timestamp
|
|
6
|
+
|
|
7
|
+
**Timestamp utilities for JavaScript.**
|
|
8
|
+
|
|
9
|
+
[](https://github.com/sapphiredev/utilities/blob/main/LICENSE.md)
|
|
10
|
+
[](https://codecov.io/gh/sapphiredev/utilities)
|
|
11
|
+
[](https://bundlephobia.com/result?p=@sapphire/timestamp)
|
|
12
|
+
[](https://www.npmjs.com/package/@sapphire/timestamp)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
**Table of Contents**
|
|
17
|
+
|
|
18
|
+
- [Features](#features)
|
|
19
|
+
- [Installation](#installation)
|
|
20
|
+
- [Usage](#usage)
|
|
21
|
+
- [Basic Usage](#basic-usage)
|
|
22
|
+
- [Buy us some doughnuts](#buy-us-some-doughnuts)
|
|
23
|
+
- [Contributors β¨](#contributors-%E2%9C%A8)
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- Written in TypeScript
|
|
28
|
+
- Bundled with esbuild so it can be used in NodeJS and browsers
|
|
29
|
+
- Offers CommonJS, ESM and UMD bundles
|
|
30
|
+
- Fully tested
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
You can use the following command to install this package, or replace `npm install` with your package manager of choice.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
npm install @sapphire/timestamp
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Buy us some doughnuts
|
|
41
|
+
|
|
42
|
+
Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!
|
|
43
|
+
|
|
44
|
+
We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.
|
|
45
|
+
|
|
46
|
+
| Donate With | Address |
|
|
47
|
+
| :-------------: | :-------------------------------------------------: |
|
|
48
|
+
| Open Collective | [Click Here](https://sapphirejs.dev/opencollective) |
|
|
49
|
+
| Ko-fi | [Click Here](https://sapphirejs.dev/kofi) |
|
|
50
|
+
| Patreon | [Click Here](https://sapphirejs.dev/patreon) |
|
|
51
|
+
| PayPal | [Click Here](https://sapphirejs.dev/paypal) |
|
|
52
|
+
|
|
53
|
+
## Contributors β¨
|
|
54
|
+
|
|
55
|
+
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
|
|
56
|
+
|
|
57
|
+
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
|
|
58
|
+
<!-- prettier-ignore-start -->
|
|
59
|
+
<!-- markdownlint-disable -->
|
|
60
|
+
<table>
|
|
61
|
+
<tr>
|
|
62
|
+
<td align="center"><a href="https://favware.tech/"><img src="https://avatars3.githubusercontent.com/u/4019718?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jeroen Claassens</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Code">π»</a> <a href="#infra-favna" title="Infrastructure (Hosting, Build-Tools, etc)">π</a> <a href="#projectManagement-favna" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=favna" title="Tests">β οΈ</a></td>
|
|
63
|
+
<td align="center"><a href="https://github.com/kyranet"><img src="https://avatars0.githubusercontent.com/u/24852502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura RomΓ‘n</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Code">π»</a> <a href="#projectManagement-kyranet" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Akyranet" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=kyranet" title="Tests">β οΈ</a></td>
|
|
64
|
+
<td align="center"><a href="https://github.com/PyroTechniac"><img src="https://avatars2.githubusercontent.com/u/39341355?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gryffon Bellish</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3APyroTechniac" title="Reviewed Pull Requests">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=PyroTechniac" title="Tests">β οΈ</a></td>
|
|
65
|
+
<td align="center"><a href="https://github.com/vladfrangu"><img src="https://avatars3.githubusercontent.com/u/17960496?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vlad Frangu</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3Avladfrangu" title="Bug reports">π</a> <a href="https://github.com/sapphiredev/utilities/pulls?q=is%3Apr+reviewed-by%3Avladfrangu" title="Reviewed Pull Requests">π</a> <a href="#userTesting-vladfrangu" title="User Testing">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=vladfrangu" title="Tests">β οΈ</a></td>
|
|
66
|
+
<td align="center"><a href="https://github.com/Stitch07"><img src="https://avatars0.githubusercontent.com/u/29275227?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stitch07</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Code">π»</a> <a href="#projectManagement-Stitch07" title="Project Management">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Stitch07" title="Tests">β οΈ</a></td>
|
|
67
|
+
<td align="center"><a href="https://github.com/apps/depfu"><img src="https://avatars3.githubusercontent.com/in/715?v=4?s=100" width="100px;" alt=""/><br /><sub><b>depfu[bot]</b></sub></a><br /><a href="#maintenance-depfu[bot]" title="Maintenance">π§</a></td>
|
|
68
|
+
<td align="center"><a href="https://github.com/apps/allcontributors"><img src="https://avatars0.githubusercontent.com/in/23186?v=4?s=100" width="100px;" alt=""/><br /><sub><b>allcontributors[bot]</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=allcontributors[bot]" title="Documentation">π</a></td>
|
|
69
|
+
</tr>
|
|
70
|
+
<tr>
|
|
71
|
+
<td align="center"><a href="https://github.com/Nytelife26"><img src="https://avatars1.githubusercontent.com/u/22531310?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tyler J Russell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Nytelife26" title="Documentation">π</a></td>
|
|
72
|
+
<td align="center"><a href="https://github.com/Alcremie"><img src="https://avatars0.githubusercontent.com/u/54785334?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ivan Lieder</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Alcremie" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AAlcremie" title="Bug reports">π</a></td>
|
|
73
|
+
<td align="center"><a href="https://github.com/RealShadowNova"><img src="https://avatars3.githubusercontent.com/u/46537907?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hezekiah Hendry</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=RealShadowNova" title="Code">π»</a> <a href="#tool-RealShadowNova" title="Tools">π§</a></td>
|
|
74
|
+
<td align="center"><a href="https://github.com/Vetlix"><img src="https://avatars.githubusercontent.com/u/31412314?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Vetlix</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Vetlix" title="Code">π»</a></td>
|
|
75
|
+
<td align="center"><a href="https://github.com/ethamitc"><img src="https://avatars.githubusercontent.com/u/27776796?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Ethan Mitchell</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ethamitc" title="Documentation">π</a></td>
|
|
76
|
+
<td align="center"><a href="https://github.com/noftaly"><img src="https://avatars.githubusercontent.com/u/34779161?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Elliot</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=noftaly" title="Code">π»</a></td>
|
|
77
|
+
<td align="center"><a href="https://jurien.dev"><img src="https://avatars.githubusercontent.com/u/5418114?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jurien Hamaker</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=jurienhamaker" title="Code">π»</a></td>
|
|
78
|
+
</tr>
|
|
79
|
+
<tr>
|
|
80
|
+
<td align="center"><a href="https://fanoulis.dev/"><img src="https://avatars.githubusercontent.com/u/38255093?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Charalampos Fanoulis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=cfanoulis" title="Documentation">π</a></td>
|
|
81
|
+
<td align="center"><a href="https://github.com/apps/dependabot"><img src="https://avatars.githubusercontent.com/in/29110?v=4?s=100" width="100px;" alt=""/><br /><sub><b>dependabot[bot]</b></sub></a><br /><a href="#maintenance-dependabot[bot]" title="Maintenance">π§</a></td>
|
|
82
|
+
<td align="center"><a href="https://kaname.netlify.app/"><img src="https://avatars.githubusercontent.com/u/56084970?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Kaname</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=kaname-png" title="Code">π»</a></td>
|
|
83
|
+
<td align="center"><a href="https://github.com/nandhagk"><img src="https://avatars.githubusercontent.com/u/62976649?v=4?s=100" width="100px;" alt=""/><br /><sub><b>nandhagk</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/issues?q=author%3Anandhagk" title="Bug reports">π</a></td>
|
|
84
|
+
<td align="center"><a href="https://megatank58.me/"><img src="https://avatars.githubusercontent.com/u/51410502?v=4?s=100" width="100px;" alt=""/><br /><sub><b>megatank58</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=megatank58" title="Code">π»</a></td>
|
|
85
|
+
<td align="center"><a href="https://github.com/UndiedGamer"><img src="https://avatars.githubusercontent.com/u/84702365?v=4?s=100" width="100px;" alt=""/><br /><sub><b>UndiedGamer</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=UndiedGamer" title="Code">π»</a></td>
|
|
86
|
+
<td align="center"><a href="https://github.com/Lioness100"><img src="https://avatars.githubusercontent.com/u/65814829?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Lioness100</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Documentation">π</a> <a href="https://github.com/sapphiredev/utilities/commits?author=Lioness100" title="Code">π»</a></td>
|
|
87
|
+
</tr>
|
|
88
|
+
<tr>
|
|
89
|
+
<td align="center"><a href="https://gitlab.com/DavidPH/"><img src="https://avatars.githubusercontent.com/u/44669930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=DavidPHH" title="Code">π»</a></td>
|
|
90
|
+
<td align="center"><a href="https://github.com/apps/renovate"><img src="https://avatars.githubusercontent.com/in/2740?v=4?s=100" width="100px;" alt=""/><br /><sub><b>renovate[bot]</b></sub></a><br /><a href="#maintenance-renovate[bot]" title="Maintenance">π§</a></td>
|
|
91
|
+
<td align="center"><a href="https://renovate.whitesourcesoftware.com/"><img src="https://avatars.githubusercontent.com/u/25180681?v=4?s=100" width="100px;" alt=""/><br /><sub><b>WhiteSource Renovate</b></sub></a><br /><a href="#maintenance-renovate-bot" title="Maintenance">π§</a></td>
|
|
92
|
+
<td align="center"><a href="https://fc5570.me/"><img src="https://avatars.githubusercontent.com/u/68158483?v=4?s=100" width="100px;" alt=""/><br /><sub><b>FC</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=FC5570" title="Code">π»</a></td>
|
|
93
|
+
<td align="center"><a href="https://github.com/Tokipudi"><img src="https://avatars.githubusercontent.com/u/29551076?v=4?s=100" width="100px;" alt=""/><br /><sub><b>JΓ©rΓ©my de Saint Denis</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Tokipudi" title="Code">π»</a></td>
|
|
94
|
+
<td align="center"><a href="https://github.com/ItsMrCube"><img src="https://avatars.githubusercontent.com/u/25201357?v=4?s=100" width="100px;" alt=""/><br /><sub><b>MrCube</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=ItsMrCube" title="Code">π»</a></td>
|
|
95
|
+
<td align="center"><a href="https://github.com/bitomic"><img src="https://avatars.githubusercontent.com/u/35199700?v=4?s=100" width="100px;" alt=""/><br /><sub><b>bitomic</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=bitomic" title="Code">π»</a></td>
|
|
96
|
+
</tr>
|
|
97
|
+
<tr>
|
|
98
|
+
<td align="center"><a href="https://c43721.dev/"><img src="https://avatars.githubusercontent.com/u/55610086?v=4?s=100" width="100px;" alt=""/><br /><sub><b>c43721</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=c43721" title="Code">π»</a></td>
|
|
99
|
+
<td align="center"><a href="https://commandtechno.com/"><img src="https://avatars.githubusercontent.com/u/68407783?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Commandtechno</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Commandtechno" title="Code">π»</a></td>
|
|
100
|
+
<td align="center"><a href="https://github.com/dhruv-kaushikk"><img src="https://avatars.githubusercontent.com/u/73697546?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aura</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=dhruv-kaushikk" title="Code">π»</a></td>
|
|
101
|
+
<td align="center"><a href="https://axis.moe/"><img src="https://avatars.githubusercontent.com/u/54381371?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Jonathan</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=axisiscool" title="Code">π»</a></td>
|
|
102
|
+
<td align="center"><a href="https://github.com/imranbarbhuiya"><img src="https://avatars.githubusercontent.com/u/74945038?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Parbez</b></sub></a><br /><a href="#maintenance-imranbarbhuiya" title="Maintenance">π§</a></td>
|
|
103
|
+
<td align="center"><a href="https://github.com/NotKaskus"><img src="https://avatars.githubusercontent.com/u/75168528?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Paul Andrew</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=NotKaskus" title="Documentation">π</a></td>
|
|
104
|
+
<td align="center"><a href="https://linktr.ee/mzato0001"><img src="https://avatars.githubusercontent.com/u/62367547?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Mzato</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=Mzato0001" title="Code">π»</a> <a href="https://github.com/sapphiredev/utilities/issues?q=author%3AMzato0001" title="Bug reports">π</a></td>
|
|
105
|
+
</tr>
|
|
106
|
+
<tr>
|
|
107
|
+
<td align="center"><a href="https://github.com/MajesticString"><img src="https://avatars.githubusercontent.com/u/66224939?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harry Allen</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=MajesticString" title="Documentation">π</a></td>
|
|
108
|
+
<td align="center"><a href="https://github.com/EvolutionX-10"><img src="https://avatars.githubusercontent.com/u/85353424?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Evo</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=EvolutionX-10" title="Code">π»</a></td>
|
|
109
|
+
<td align="center"><a href="https://enes.ovh/"><img src="https://avatars.githubusercontent.com/u/61084101?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Enes GenΓ§</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=enxg" title="Code">π»</a></td>
|
|
110
|
+
<td align="center"><a href="https://github.com/muchnameless"><img src="https://avatars.githubusercontent.com/u/12682826?v=4?s=100" width="100px;" alt=""/><br /><sub><b>muchnameless</b></sub></a><br /><a href="https://github.com/sapphiredev/utilities/commits?author=muchnameless" title="Code">π»</a></td>
|
|
111
|
+
</tr>
|
|
112
|
+
</table>
|
|
113
|
+
|
|
114
|
+
<!-- markdownlint-restore -->
|
|
115
|
+
<!-- prettier-ignore-end -->
|
|
116
|
+
|
|
117
|
+
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
118
|
+
|
|
119
|
+
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
declare enum Time {
|
|
2
|
+
Millisecond = 1,
|
|
3
|
+
Second = 1000,
|
|
4
|
+
Minute = 60000,
|
|
5
|
+
Hour = 3600000,
|
|
6
|
+
Day = 86400000,
|
|
7
|
+
Month = 2628000000,
|
|
8
|
+
Year = 31536000000
|
|
9
|
+
}
|
|
10
|
+
declare const days: string[];
|
|
11
|
+
declare const months: string[];
|
|
12
|
+
declare const tokens: Map<string, number>;
|
|
13
|
+
|
|
14
|
+
declare type TimeResolvable = Date | number | string;
|
|
15
|
+
interface TimestampTemplateEntry {
|
|
16
|
+
type: string;
|
|
17
|
+
content: string | null;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Timestamp class, parses the pattern once, displays the desired Date or UNIX timestamp with the selected pattern.
|
|
21
|
+
*/
|
|
22
|
+
declare class Timestamp {
|
|
23
|
+
/**
|
|
24
|
+
* The raw pattern
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
*/
|
|
27
|
+
pattern: string;
|
|
28
|
+
/**
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
31
|
+
private template;
|
|
32
|
+
/**
|
|
33
|
+
* Starts a new Timestamp and parses the pattern.
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
* @param pattern The pattern to parse
|
|
36
|
+
*/
|
|
37
|
+
constructor(pattern: string);
|
|
38
|
+
/**
|
|
39
|
+
* Display the current date with the current pattern.
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
* @param time The time to display
|
|
42
|
+
*/
|
|
43
|
+
display(time?: TimeResolvable): string;
|
|
44
|
+
/**
|
|
45
|
+
* Display the current date utc with the current pattern.
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
* @param time The time to display in utc
|
|
48
|
+
*/
|
|
49
|
+
displayUTC(time?: TimeResolvable): string;
|
|
50
|
+
/**
|
|
51
|
+
* Edits the current pattern.
|
|
52
|
+
* @since 1.0.0
|
|
53
|
+
* @param pattern The new pattern for this instance
|
|
54
|
+
* @chainable
|
|
55
|
+
*/
|
|
56
|
+
edit(pattern: string): this;
|
|
57
|
+
/**
|
|
58
|
+
* Defines the toString behavior of Timestamp.
|
|
59
|
+
*/
|
|
60
|
+
toString(): string;
|
|
61
|
+
/**
|
|
62
|
+
* Display the current date with the current pattern.
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
* @param pattern The pattern to parse
|
|
65
|
+
* @param time The time to display
|
|
66
|
+
*/
|
|
67
|
+
static displayArbitrary(pattern: string, time?: TimeResolvable): string;
|
|
68
|
+
/**
|
|
69
|
+
* Display the current date utc with the current pattern.
|
|
70
|
+
* @since 1.0.0
|
|
71
|
+
* @param pattern The pattern to parse
|
|
72
|
+
* @param time The time to display
|
|
73
|
+
*/
|
|
74
|
+
static displayUTCArbitrary(pattern: string, time?: TimeResolvable): string;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a UTC Date object to work with.
|
|
77
|
+
* @since 1.0.0
|
|
78
|
+
* @param time The date to convert to utc
|
|
79
|
+
*/
|
|
80
|
+
static utc(time?: Date | number | string): Date;
|
|
81
|
+
/**
|
|
82
|
+
* Display the current date with the current pattern.
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @param template The pattern to parse
|
|
85
|
+
* @param time The time to display
|
|
86
|
+
*/
|
|
87
|
+
private static display;
|
|
88
|
+
/**
|
|
89
|
+
* Parses the pattern.
|
|
90
|
+
* @since 1.0.0
|
|
91
|
+
* @param pattern The pattern to parse
|
|
92
|
+
*/
|
|
93
|
+
private static parse;
|
|
94
|
+
/**
|
|
95
|
+
* Resolves a date.
|
|
96
|
+
* @since 1.0.0
|
|
97
|
+
* @param time The time to parse
|
|
98
|
+
*/
|
|
99
|
+
private static resolveDate;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { Time, TimeResolvable, Timestamp, TimestampTemplateEntry, days, months, tokens };
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var SapphireTimestamp = (() => {
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
Time: () => Time,
|
|
31
|
+
Timestamp: () => Timestamp,
|
|
32
|
+
days: () => days,
|
|
33
|
+
months: () => months,
|
|
34
|
+
tokens: () => tokens
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// src/lib/constants.ts
|
|
38
|
+
var Time = /* @__PURE__ */ ((Time2) => {
|
|
39
|
+
Time2[Time2["Millisecond"] = 1] = "Millisecond";
|
|
40
|
+
Time2[Time2["Second"] = 1e3] = "Second";
|
|
41
|
+
Time2[Time2["Minute"] = 6e4] = "Minute";
|
|
42
|
+
Time2[Time2["Hour"] = 36e5] = "Hour";
|
|
43
|
+
Time2[Time2["Day"] = 864e5] = "Day";
|
|
44
|
+
Time2[Time2["Month"] = 2628e6] = "Month";
|
|
45
|
+
Time2[Time2["Year"] = 31536e6] = "Year";
|
|
46
|
+
return Time2;
|
|
47
|
+
})(Time || {});
|
|
48
|
+
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
49
|
+
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
50
|
+
var tokens = /* @__PURE__ */ new Map([
|
|
51
|
+
["Y", 4],
|
|
52
|
+
["Q", 1],
|
|
53
|
+
["M", 4],
|
|
54
|
+
["D", 4],
|
|
55
|
+
["d", 4],
|
|
56
|
+
["X", 1],
|
|
57
|
+
["x", 1],
|
|
58
|
+
["H", 2],
|
|
59
|
+
["h", 2],
|
|
60
|
+
["a", 1],
|
|
61
|
+
["A", 1],
|
|
62
|
+
["m", 2],
|
|
63
|
+
["s", 2],
|
|
64
|
+
["S", 3],
|
|
65
|
+
["Z", 2],
|
|
66
|
+
["l", 4],
|
|
67
|
+
["L", 4],
|
|
68
|
+
["T", 1],
|
|
69
|
+
["t", 1]
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
// src/lib/Timestamp.ts
|
|
73
|
+
var tokenResolvers = /* @__PURE__ */ new Map([
|
|
74
|
+
["Y", (time) => String(time.getFullYear()).slice(2)],
|
|
75
|
+
["YY", (time) => String(time.getFullYear()).slice(2)],
|
|
76
|
+
["YYY", (time) => String(time.getFullYear())],
|
|
77
|
+
["YYYY", (time) => String(time.getFullYear())],
|
|
78
|
+
["Q", (time) => String((time.getMonth() + 1) / 3)],
|
|
79
|
+
["M", (time) => String(time.getMonth() + 1)],
|
|
80
|
+
["MM", (time) => String(time.getMonth() + 1).padStart(2, "0")],
|
|
81
|
+
["MMM", (time) => months[time.getMonth()]],
|
|
82
|
+
["MMMM", (time) => months[time.getMonth()]],
|
|
83
|
+
["D", (time) => String(time.getDate())],
|
|
84
|
+
["DD", (time) => String(time.getDate()).padStart(2, "0")],
|
|
85
|
+
["DDD", (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / 864e5 /* Day */))],
|
|
86
|
+
["DDDD", (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / 864e5 /* Day */))],
|
|
87
|
+
[
|
|
88
|
+
"d",
|
|
89
|
+
(time) => {
|
|
90
|
+
const day = String(time.getDate());
|
|
91
|
+
if (day !== "11" && day.endsWith("1"))
|
|
92
|
+
return `${day}st`;
|
|
93
|
+
if (day !== "12" && day.endsWith("2"))
|
|
94
|
+
return `${day}nd`;
|
|
95
|
+
if (day !== "13" && day.endsWith("3"))
|
|
96
|
+
return `${day}rd`;
|
|
97
|
+
return `${day}th`;
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
["dd", (time) => days[time.getDay()].slice(0, 2)],
|
|
101
|
+
["ddd", (time) => days[time.getDay()].slice(0, 3)],
|
|
102
|
+
["dddd", (time) => days[time.getDay()]],
|
|
103
|
+
["X", (time) => String(time.valueOf() / 1e3 /* Second */)],
|
|
104
|
+
["x", (time) => String(time.valueOf())],
|
|
105
|
+
["H", (time) => String(time.getHours())],
|
|
106
|
+
["HH", (time) => String(time.getHours()).padStart(2, "0")],
|
|
107
|
+
["h", (time) => String(time.getHours() % 12 || 12)],
|
|
108
|
+
["hh", (time) => String(time.getHours() % 12 || 12).padStart(2, "0")],
|
|
109
|
+
["a", (time) => time.getHours() < 12 ? "am" : "pm"],
|
|
110
|
+
["A", (time) => time.getHours() < 12 ? "AM" : "PM"],
|
|
111
|
+
["m", (time) => String(time.getMinutes())],
|
|
112
|
+
["mm", (time) => String(time.getMinutes()).padStart(2, "0")],
|
|
113
|
+
["s", (time) => String(time.getSeconds())],
|
|
114
|
+
["ss", (time) => String(time.getSeconds()).padStart(2, "0")],
|
|
115
|
+
["S", (time) => String(time.getMilliseconds())],
|
|
116
|
+
["SS", (time) => String(time.getMilliseconds()).padStart(2, "0")],
|
|
117
|
+
["SSS", (time) => String(time.getMilliseconds()).padStart(3, "0")],
|
|
118
|
+
["T", (time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`],
|
|
119
|
+
[
|
|
120
|
+
"t",
|
|
121
|
+
(time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")}:${String(time.getSeconds()).padStart(2, "0")} ${time.getHours() < 12 ? "am" : "pm"}`
|
|
122
|
+
],
|
|
123
|
+
["L", (time) => `${String(time.getMonth() + 1).padStart(2, "0")}/${String(time.getDate()).padStart(2, "0")}/${String(time.getFullYear())}`],
|
|
124
|
+
["l", (time) => `${String(time.getMonth() + 1)}/${String(time.getDate()).padStart(2, "0")}/${String(time.getFullYear())}`],
|
|
125
|
+
["LL", (time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())}`],
|
|
126
|
+
["ll", (time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())}`],
|
|
127
|
+
[
|
|
128
|
+
"LLL",
|
|
129
|
+
(time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
130
|
+
time.getHours() % 12 || 12
|
|
131
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
"lll",
|
|
135
|
+
(time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
136
|
+
time.getHours() % 12 || 12
|
|
137
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
"LLLL",
|
|
141
|
+
(time) => `${days[time.getDay()]}, ${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
142
|
+
time.getHours() % 12 || 12
|
|
143
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
"llll",
|
|
147
|
+
(time) => `${days[time.getDay()].slice(0, 3)} ${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(
|
|
148
|
+
time.getFullYear()
|
|
149
|
+
)} ${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
150
|
+
],
|
|
151
|
+
[
|
|
152
|
+
"Z",
|
|
153
|
+
(time) => {
|
|
154
|
+
const offset = time.getTimezoneOffset();
|
|
155
|
+
const unsigned = offset >= 0;
|
|
156
|
+
const absolute = Math.abs(offset);
|
|
157
|
+
return `${unsigned ? "+" : "-"}${String(Math.floor(absolute / 60)).padStart(2, "0")}:${String(absolute % 60).padStart(2, "0")}`;
|
|
158
|
+
}
|
|
159
|
+
],
|
|
160
|
+
[
|
|
161
|
+
"ZZ",
|
|
162
|
+
(time) => {
|
|
163
|
+
const offset = time.getTimezoneOffset();
|
|
164
|
+
const unsigned = offset >= 0;
|
|
165
|
+
const absolute = Math.abs(offset);
|
|
166
|
+
return `${unsigned ? "+" : "-"}${String(Math.floor(absolute / 60)).padStart(2, "0")}:${String(absolute % 60).padStart(2, "0")}`;
|
|
167
|
+
}
|
|
168
|
+
]
|
|
169
|
+
]);
|
|
170
|
+
var Timestamp = class {
|
|
171
|
+
constructor(pattern) {
|
|
172
|
+
__publicField(this, "pattern");
|
|
173
|
+
__publicField(this, "template");
|
|
174
|
+
this.pattern = pattern;
|
|
175
|
+
this.template = Timestamp.parse(pattern);
|
|
176
|
+
}
|
|
177
|
+
display(time = new Date()) {
|
|
178
|
+
return Timestamp.display(this.template, time);
|
|
179
|
+
}
|
|
180
|
+
displayUTC(time) {
|
|
181
|
+
return Timestamp.display(this.template, Timestamp.utc(time));
|
|
182
|
+
}
|
|
183
|
+
edit(pattern) {
|
|
184
|
+
this.pattern = pattern;
|
|
185
|
+
this.template = Timestamp.parse(pattern);
|
|
186
|
+
return this;
|
|
187
|
+
}
|
|
188
|
+
toString() {
|
|
189
|
+
return this.display();
|
|
190
|
+
}
|
|
191
|
+
static displayArbitrary(pattern, time = new Date()) {
|
|
192
|
+
return Timestamp.display(Timestamp.parse(pattern), time);
|
|
193
|
+
}
|
|
194
|
+
static displayUTCArbitrary(pattern, time = new Date()) {
|
|
195
|
+
return Timestamp.display(Timestamp.parse(pattern), Timestamp.utc(time));
|
|
196
|
+
}
|
|
197
|
+
static utc(time = new Date()) {
|
|
198
|
+
time = Timestamp.resolveDate(time);
|
|
199
|
+
return new Date(time.valueOf() + time.getTimezoneOffset() * 6e4);
|
|
200
|
+
}
|
|
201
|
+
static display(template, time) {
|
|
202
|
+
let output = "";
|
|
203
|
+
const parsedTime = Timestamp.resolveDate(time);
|
|
204
|
+
for (const { content, type } of template)
|
|
205
|
+
output += content || tokenResolvers.get(type)(parsedTime);
|
|
206
|
+
return output;
|
|
207
|
+
}
|
|
208
|
+
static parse(pattern) {
|
|
209
|
+
const template = [];
|
|
210
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
211
|
+
let current = "";
|
|
212
|
+
const currentChar = pattern[i];
|
|
213
|
+
const tokenMax = tokens.get(currentChar);
|
|
214
|
+
if (typeof tokenMax === "number") {
|
|
215
|
+
current += currentChar;
|
|
216
|
+
while (pattern[i + 1] === currentChar && current.length < tokenMax)
|
|
217
|
+
current += pattern[++i];
|
|
218
|
+
template.push({ type: current, content: null });
|
|
219
|
+
} else if (currentChar === "[") {
|
|
220
|
+
while (i + 1 < pattern.length && pattern[i + 1] !== "]")
|
|
221
|
+
current += pattern[++i];
|
|
222
|
+
i++;
|
|
223
|
+
template.push({ type: "literal", content: current || "[" });
|
|
224
|
+
} else {
|
|
225
|
+
current += currentChar;
|
|
226
|
+
while (i + 1 < pattern.length && !tokens.has(pattern[i + 1]) && pattern[i + 1] !== "[")
|
|
227
|
+
current += pattern[++i];
|
|
228
|
+
template.push({ type: "literal", content: current });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return template;
|
|
232
|
+
}
|
|
233
|
+
static resolveDate(time) {
|
|
234
|
+
return time instanceof Date ? time : new Date(time);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
__name(Timestamp, "Timestamp");
|
|
238
|
+
return __toCommonJS(src_exports);
|
|
239
|
+
})();
|
|
240
|
+
//# sourceMappingURL=index.global.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/constants.ts","../src/lib/Timestamp.ts"],"sourcesContent":["export * from './lib/constants';\nexport * from './lib/Timestamp';\n","export enum Time {\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = 1000 * 60,\n\tHour = 1000 * 60 * 60,\n\tDay = 1000 * 60 * 60 * 24,\n\tMonth = 1000 * 60 * 60 * 24 * (365 / 12),\n\tYear = 1000 * 60 * 60 * 24 * 365\n}\n\nexport const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\n\nexport const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n\nexport const tokens = new Map<string, number>([\n\t['Y', 4],\n\t['Q', 1],\n\t['M', 4],\n\t['D', 4],\n\t['d', 4],\n\t['X', 1],\n\t['x', 1],\n\t['H', 2],\n\t['h', 2],\n\t['a', 1],\n\t['A', 1],\n\t['m', 2],\n\t['s', 2],\n\t['S', 3],\n\t['Z', 2],\n\t['l', 4],\n\t['L', 4],\n\t['T', 1],\n\t['t', 1]\n]);\n","import { days, months, Time, tokens } from './constants';\n\ninterface TokenResolver {\n\t(time: Date): string;\n}\n\nconst tokenResolvers = new Map<string, TokenResolver>([\n\t// Dates\n\t['Y', (time) => String(time.getFullYear()).slice(2)],\n\t['YY', (time) => String(time.getFullYear()).slice(2)],\n\t['YYY', (time) => String(time.getFullYear())],\n\t['YYYY', (time) => String(time.getFullYear())],\n\t['Q', (time) => String((time.getMonth() + 1) / 3)],\n\t['M', (time) => String(time.getMonth() + 1)],\n\t['MM', (time) => String(time.getMonth() + 1).padStart(2, '0')],\n\t['MMM', (time) => months[time.getMonth()]],\n\t['MMMM', (time) => months[time.getMonth()]],\n\t['D', (time) => String(time.getDate())],\n\t['DD', (time) => String(time.getDate()).padStart(2, '0')],\n\t['DDD', (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / Time.Day))],\n\t['DDDD', (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / Time.Day))],\n\t[\n\t\t'd',\n\t\t(time) => {\n\t\t\tconst day = String(time.getDate());\n\t\t\tif (day !== '11' && day.endsWith('1')) return `${day}st`;\n\t\t\tif (day !== '12' && day.endsWith('2')) return `${day}nd`;\n\t\t\tif (day !== '13' && day.endsWith('3')) return `${day}rd`;\n\t\t\treturn `${day}th`;\n\t\t}\n\t],\n\t['dd', (time) => days[time.getDay()].slice(0, 2)],\n\t['ddd', (time) => days[time.getDay()].slice(0, 3)],\n\t['dddd', (time) => days[time.getDay()]],\n\t['X', (time) => String(time.valueOf() / Time.Second)],\n\t['x', (time) => String(time.valueOf())],\n\n\t// Locales\n\t['H', (time) => String(time.getHours())],\n\t['HH', (time) => String(time.getHours()).padStart(2, '0')],\n\t['h', (time) => String(time.getHours() % 12 || 12)],\n\t['hh', (time) => String(time.getHours() % 12 || 12).padStart(2, '0')],\n\t['a', (time) => (time.getHours() < 12 ? 'am' : 'pm')],\n\t['A', (time) => (time.getHours() < 12 ? 'AM' : 'PM')],\n\t['m', (time) => String(time.getMinutes())],\n\t['mm', (time) => String(time.getMinutes()).padStart(2, '0')],\n\t['s', (time) => String(time.getSeconds())],\n\t['ss', (time) => String(time.getSeconds()).padStart(2, '0')],\n\t['S', (time) => String(time.getMilliseconds())],\n\t['SS', (time) => String(time.getMilliseconds()).padStart(2, '0')],\n\t['SSS', (time) => String(time.getMilliseconds()).padStart(3, '0')],\n\t['T', (time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`],\n\t[\n\t\t't',\n\t\t(time) =>\n\t\t\t`${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')}:${String(time.getSeconds()).padStart(2, '0')} ${\n\t\t\t\ttime.getHours() < 12 ? 'am' : 'pm'\n\t\t\t}`\n\t],\n\t['L', (time) => `${String(time.getMonth() + 1).padStart(2, '0')}/${String(time.getDate()).padStart(2, '0')}/${String(time.getFullYear())}`],\n\t['l', (time) => `${String(time.getMonth() + 1)}/${String(time.getDate()).padStart(2, '0')}/${String(time.getFullYear())}`],\n\t['LL', (time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())}`],\n\t['ll', (time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())}`],\n\t[\n\t\t'LLL',\n\t\t(time) =>\n\t\t\t`${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'lll',\n\t\t(time) =>\n\t\t\t`${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'LLLL',\n\t\t(time) =>\n\t\t\t`${days[time.getDay()]}, ${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'llll',\n\t\t(time) =>\n\t\t\t`${days[time.getDay()].slice(0, 3)} ${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(\n\t\t\t\ttime.getFullYear()\n\t\t\t)} ${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'Z',\n\t\t(time) => {\n\t\t\tconst offset = time.getTimezoneOffset();\n\t\t\tconst unsigned = offset >= 0;\n\t\t\tconst absolute = Math.abs(offset);\n\t\t\t/* istanbul ignore next: whether it's signed or unsigned, depends on where the machine is, I cannot control this. */\n\t\t\treturn `${unsigned ? '+' : '-'}${String(Math.floor(absolute / 60)).padStart(2, '0')}:${String(absolute % 60).padStart(2, '0')}`;\n\t\t}\n\t],\n\t[\n\t\t'ZZ',\n\t\t(time) => {\n\t\t\tconst offset = time.getTimezoneOffset();\n\t\t\tconst unsigned = offset >= 0;\n\t\t\tconst absolute = Math.abs(offset);\n\t\t\t/* istanbul ignore next: whether it's signed or unsigned, depends on where the machine is, I cannot control this. */\n\t\t\treturn `${unsigned ? '+' : '-'}${String(Math.floor(absolute / 60)).padStart(2, '0')}:${String(absolute % 60).padStart(2, '0')}`;\n\t\t}\n\t]\n]);\n/* eslint-enable max-len */\n\nexport type TimeResolvable = Date | number | string;\n\nexport interface TimestampTemplateEntry {\n\ttype: string;\n\tcontent: string | null;\n}\n\n/**\n * Timestamp class, parses the pattern once, displays the desired Date or UNIX timestamp with the selected pattern.\n */\nexport class Timestamp {\n\t/**\n\t * The raw pattern\n\t * @since 1.0.0\n\t */\n\tpublic pattern: string;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate template: TimestampTemplateEntry[];\n\n\t/**\n\t * Starts a new Timestamp and parses the pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t */\n\tpublic constructor(pattern: string) {\n\t\tthis.pattern = pattern;\n\t\tthis.template = Timestamp.parse(pattern);\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param time The time to display\n\t */\n\tpublic display(time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(this.template, time);\n\t}\n\n\t/**\n\t * Display the current date utc with the current pattern.\n\t * @since 1.0.0\n\t * @param time The time to display in utc\n\t */\n\tpublic displayUTC(time?: TimeResolvable): string {\n\t\treturn Timestamp.display(this.template, Timestamp.utc(time));\n\t}\n\n\t/**\n\t * Edits the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The new pattern for this instance\n\t * @chainable\n\t */\n\tpublic edit(pattern: string): this {\n\t\tthis.pattern = pattern;\n\t\tthis.template = Timestamp.parse(pattern);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Defines the toString behavior of Timestamp.\n\t */\n\tpublic toString(): string {\n\t\treturn this.display();\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t * @param time The time to display\n\t */\n\tpublic static displayArbitrary(pattern: string, time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(Timestamp.parse(pattern), time);\n\t}\n\n\t/**\n\t * Display the current date utc with the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t * @param time The time to display\n\t */\n\tpublic static displayUTCArbitrary(pattern: string, time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(Timestamp.parse(pattern), Timestamp.utc(time));\n\t}\n\n\t/**\n\t * Creates a UTC Date object to work with.\n\t * @since 1.0.0\n\t * @param time The date to convert to utc\n\t */\n\tpublic static utc(time: Date | number | string = new Date()): Date {\n\t\ttime = Timestamp.resolveDate(time);\n\t\treturn new Date(time.valueOf() + time.getTimezoneOffset() * 60000);\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param template The pattern to parse\n\t * @param time The time to display\n\t */\n\tprivate static display(template: TimestampTemplateEntry[], time: Date | number | string): string {\n\t\tlet output = '';\n\t\tconst parsedTime = Timestamp.resolveDate(time);\n\t\tfor (const { content, type } of template) output += content || tokenResolvers.get(type)!(parsedTime);\n\t\treturn output;\n\t}\n\n\t/**\n\t * Parses the pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t */\n\tprivate static parse(pattern: string): TimestampTemplateEntry[] {\n\t\tconst template: TimestampTemplateEntry[] = [];\n\t\tfor (let i = 0; i < pattern.length; i++) {\n\t\t\tlet current = '';\n\t\t\tconst currentChar = pattern[i];\n\t\t\tconst tokenMax = tokens.get(currentChar);\n\t\t\tif (typeof tokenMax === 'number') {\n\t\t\t\tcurrent += currentChar;\n\t\t\t\twhile (pattern[i + 1] === currentChar && current.length < tokenMax) current += pattern[++i];\n\t\t\t\ttemplate.push({ type: current, content: null });\n\t\t\t} else if (currentChar === '[') {\n\t\t\t\twhile (i + 1 < pattern.length && pattern[i + 1] !== ']') current += pattern[++i];\n\t\t\t\ti++;\n\t\t\t\ttemplate.push({ type: 'literal', content: current || '[' });\n\t\t\t} else {\n\t\t\t\tcurrent += currentChar;\n\t\t\t\twhile (i + 1 < pattern.length && !tokens.has(pattern[i + 1]) && pattern[i + 1] !== '[') current += pattern[++i];\n\t\t\t\ttemplate.push({ type: 'literal', content: current });\n\t\t\t}\n\t\t}\n\n\t\treturn template;\n\t}\n\n\t/**\n\t * Resolves a date.\n\t * @since 1.0.0\n\t * @param time The time to parse\n\t */\n\tprivate static resolveDate(time: TimeResolvable): Date {\n\t\treturn time instanceof Date ? time : new Date(time);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,MAAK,OAAL,kBAAKA,UAAL;AACN,IAAAA,YAAA,iBAAc,KAAd;AACA,IAAAA,YAAA,YAAS,OAAT;AACA,IAAAA,YAAA,YAAS,OAAT;AACA,IAAAA,YAAA,UAAO,QAAP;AACA,IAAAA,YAAA,SAAM,SAAN;AACA,IAAAA,YAAA,WAAQ,UAAR;AACA,IAAAA,YAAA,UAAO,WAAP;AAPW,WAAAA;AAAA,KAAA;AAUL,MAAM,OAAO,CAAC,UAAU,UAAU,WAAW,aAAa,YAAY,UAAU,UAAU;AAE1F,MAAM,SAAS,CAAC,WAAW,YAAY,SAAS,SAAS,OAAO,QAAQ,QAAQ,UAAU,aAAa,WAAW,YAAY,UAAU;AAExI,MAAM,SAAS,oBAAI,IAAoB;AAAA,IAC7C,CAAC,KAAK,CAAC;AAAA,IACP,CAAC,KAAK,CAAC;AAAA,IACP,CAAC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"use strict";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var __publicField = (obj, key, value) => {
|
|
23
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
24
|
+
return value;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/index.ts
|
|
28
|
+
var src_exports = {};
|
|
29
|
+
__export(src_exports, {
|
|
30
|
+
Time: () => Time,
|
|
31
|
+
Timestamp: () => Timestamp,
|
|
32
|
+
days: () => days,
|
|
33
|
+
months: () => months,
|
|
34
|
+
tokens: () => tokens
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
|
|
38
|
+
// src/lib/constants.ts
|
|
39
|
+
var Time = /* @__PURE__ */ ((Time2) => {
|
|
40
|
+
Time2[Time2["Millisecond"] = 1] = "Millisecond";
|
|
41
|
+
Time2[Time2["Second"] = 1e3] = "Second";
|
|
42
|
+
Time2[Time2["Minute"] = 6e4] = "Minute";
|
|
43
|
+
Time2[Time2["Hour"] = 36e5] = "Hour";
|
|
44
|
+
Time2[Time2["Day"] = 864e5] = "Day";
|
|
45
|
+
Time2[Time2["Month"] = 2628e6] = "Month";
|
|
46
|
+
Time2[Time2["Year"] = 31536e6] = "Year";
|
|
47
|
+
return Time2;
|
|
48
|
+
})(Time || {});
|
|
49
|
+
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
50
|
+
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
51
|
+
var tokens = /* @__PURE__ */ new Map([
|
|
52
|
+
["Y", 4],
|
|
53
|
+
["Q", 1],
|
|
54
|
+
["M", 4],
|
|
55
|
+
["D", 4],
|
|
56
|
+
["d", 4],
|
|
57
|
+
["X", 1],
|
|
58
|
+
["x", 1],
|
|
59
|
+
["H", 2],
|
|
60
|
+
["h", 2],
|
|
61
|
+
["a", 1],
|
|
62
|
+
["A", 1],
|
|
63
|
+
["m", 2],
|
|
64
|
+
["s", 2],
|
|
65
|
+
["S", 3],
|
|
66
|
+
["Z", 2],
|
|
67
|
+
["l", 4],
|
|
68
|
+
["L", 4],
|
|
69
|
+
["T", 1],
|
|
70
|
+
["t", 1]
|
|
71
|
+
]);
|
|
72
|
+
|
|
73
|
+
// src/lib/Timestamp.ts
|
|
74
|
+
var tokenResolvers = /* @__PURE__ */ new Map([
|
|
75
|
+
["Y", (time) => String(time.getFullYear()).slice(2)],
|
|
76
|
+
["YY", (time) => String(time.getFullYear()).slice(2)],
|
|
77
|
+
["YYY", (time) => String(time.getFullYear())],
|
|
78
|
+
["YYYY", (time) => String(time.getFullYear())],
|
|
79
|
+
["Q", (time) => String((time.getMonth() + 1) / 3)],
|
|
80
|
+
["M", (time) => String(time.getMonth() + 1)],
|
|
81
|
+
["MM", (time) => String(time.getMonth() + 1).padStart(2, "0")],
|
|
82
|
+
["MMM", (time) => months[time.getMonth()]],
|
|
83
|
+
["MMMM", (time) => months[time.getMonth()]],
|
|
84
|
+
["D", (time) => String(time.getDate())],
|
|
85
|
+
["DD", (time) => String(time.getDate()).padStart(2, "0")],
|
|
86
|
+
["DDD", (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / 864e5 /* Day */))],
|
|
87
|
+
["DDDD", (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / 864e5 /* Day */))],
|
|
88
|
+
[
|
|
89
|
+
"d",
|
|
90
|
+
(time) => {
|
|
91
|
+
const day = String(time.getDate());
|
|
92
|
+
if (day !== "11" && day.endsWith("1"))
|
|
93
|
+
return `${day}st`;
|
|
94
|
+
if (day !== "12" && day.endsWith("2"))
|
|
95
|
+
return `${day}nd`;
|
|
96
|
+
if (day !== "13" && day.endsWith("3"))
|
|
97
|
+
return `${day}rd`;
|
|
98
|
+
return `${day}th`;
|
|
99
|
+
}
|
|
100
|
+
],
|
|
101
|
+
["dd", (time) => days[time.getDay()].slice(0, 2)],
|
|
102
|
+
["ddd", (time) => days[time.getDay()].slice(0, 3)],
|
|
103
|
+
["dddd", (time) => days[time.getDay()]],
|
|
104
|
+
["X", (time) => String(time.valueOf() / 1e3 /* Second */)],
|
|
105
|
+
["x", (time) => String(time.valueOf())],
|
|
106
|
+
["H", (time) => String(time.getHours())],
|
|
107
|
+
["HH", (time) => String(time.getHours()).padStart(2, "0")],
|
|
108
|
+
["h", (time) => String(time.getHours() % 12 || 12)],
|
|
109
|
+
["hh", (time) => String(time.getHours() % 12 || 12).padStart(2, "0")],
|
|
110
|
+
["a", (time) => time.getHours() < 12 ? "am" : "pm"],
|
|
111
|
+
["A", (time) => time.getHours() < 12 ? "AM" : "PM"],
|
|
112
|
+
["m", (time) => String(time.getMinutes())],
|
|
113
|
+
["mm", (time) => String(time.getMinutes()).padStart(2, "0")],
|
|
114
|
+
["s", (time) => String(time.getSeconds())],
|
|
115
|
+
["ss", (time) => String(time.getSeconds()).padStart(2, "0")],
|
|
116
|
+
["S", (time) => String(time.getMilliseconds())],
|
|
117
|
+
["SS", (time) => String(time.getMilliseconds()).padStart(2, "0")],
|
|
118
|
+
["SSS", (time) => String(time.getMilliseconds()).padStart(3, "0")],
|
|
119
|
+
["T", (time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`],
|
|
120
|
+
[
|
|
121
|
+
"t",
|
|
122
|
+
(time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")}:${String(time.getSeconds()).padStart(2, "0")} ${time.getHours() < 12 ? "am" : "pm"}`
|
|
123
|
+
],
|
|
124
|
+
["L", (time) => `${String(time.getMonth() + 1).padStart(2, "0")}/${String(time.getDate()).padStart(2, "0")}/${String(time.getFullYear())}`],
|
|
125
|
+
["l", (time) => `${String(time.getMonth() + 1)}/${String(time.getDate()).padStart(2, "0")}/${String(time.getFullYear())}`],
|
|
126
|
+
["LL", (time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())}`],
|
|
127
|
+
["ll", (time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())}`],
|
|
128
|
+
[
|
|
129
|
+
"LLL",
|
|
130
|
+
(time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
131
|
+
time.getHours() % 12 || 12
|
|
132
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
"lll",
|
|
136
|
+
(time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
137
|
+
time.getHours() % 12 || 12
|
|
138
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
"LLLL",
|
|
142
|
+
(time) => `${days[time.getDay()]}, ${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
143
|
+
time.getHours() % 12 || 12
|
|
144
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
"llll",
|
|
148
|
+
(time) => `${days[time.getDay()].slice(0, 3)} ${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(
|
|
149
|
+
time.getFullYear()
|
|
150
|
+
)} ${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
151
|
+
],
|
|
152
|
+
[
|
|
153
|
+
"Z",
|
|
154
|
+
(time) => {
|
|
155
|
+
const offset = time.getTimezoneOffset();
|
|
156
|
+
const unsigned = offset >= 0;
|
|
157
|
+
const absolute = Math.abs(offset);
|
|
158
|
+
return `${unsigned ? "+" : "-"}${String(Math.floor(absolute / 60)).padStart(2, "0")}:${String(absolute % 60).padStart(2, "0")}`;
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
"ZZ",
|
|
163
|
+
(time) => {
|
|
164
|
+
const offset = time.getTimezoneOffset();
|
|
165
|
+
const unsigned = offset >= 0;
|
|
166
|
+
const absolute = Math.abs(offset);
|
|
167
|
+
return `${unsigned ? "+" : "-"}${String(Math.floor(absolute / 60)).padStart(2, "0")}:${String(absolute % 60).padStart(2, "0")}`;
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
]);
|
|
171
|
+
var Timestamp = class {
|
|
172
|
+
constructor(pattern) {
|
|
173
|
+
__publicField(this, "pattern");
|
|
174
|
+
__publicField(this, "template");
|
|
175
|
+
this.pattern = pattern;
|
|
176
|
+
this.template = Timestamp.parse(pattern);
|
|
177
|
+
}
|
|
178
|
+
display(time = new Date()) {
|
|
179
|
+
return Timestamp.display(this.template, time);
|
|
180
|
+
}
|
|
181
|
+
displayUTC(time) {
|
|
182
|
+
return Timestamp.display(this.template, Timestamp.utc(time));
|
|
183
|
+
}
|
|
184
|
+
edit(pattern) {
|
|
185
|
+
this.pattern = pattern;
|
|
186
|
+
this.template = Timestamp.parse(pattern);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
toString() {
|
|
190
|
+
return this.display();
|
|
191
|
+
}
|
|
192
|
+
static displayArbitrary(pattern, time = new Date()) {
|
|
193
|
+
return Timestamp.display(Timestamp.parse(pattern), time);
|
|
194
|
+
}
|
|
195
|
+
static displayUTCArbitrary(pattern, time = new Date()) {
|
|
196
|
+
return Timestamp.display(Timestamp.parse(pattern), Timestamp.utc(time));
|
|
197
|
+
}
|
|
198
|
+
static utc(time = new Date()) {
|
|
199
|
+
time = Timestamp.resolveDate(time);
|
|
200
|
+
return new Date(time.valueOf() + time.getTimezoneOffset() * 6e4);
|
|
201
|
+
}
|
|
202
|
+
static display(template, time) {
|
|
203
|
+
let output = "";
|
|
204
|
+
const parsedTime = Timestamp.resolveDate(time);
|
|
205
|
+
for (const { content, type } of template)
|
|
206
|
+
output += content || tokenResolvers.get(type)(parsedTime);
|
|
207
|
+
return output;
|
|
208
|
+
}
|
|
209
|
+
static parse(pattern) {
|
|
210
|
+
const template = [];
|
|
211
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
212
|
+
let current = "";
|
|
213
|
+
const currentChar = pattern[i];
|
|
214
|
+
const tokenMax = tokens.get(currentChar);
|
|
215
|
+
if (typeof tokenMax === "number") {
|
|
216
|
+
current += currentChar;
|
|
217
|
+
while (pattern[i + 1] === currentChar && current.length < tokenMax)
|
|
218
|
+
current += pattern[++i];
|
|
219
|
+
template.push({ type: current, content: null });
|
|
220
|
+
} else if (currentChar === "[") {
|
|
221
|
+
while (i + 1 < pattern.length && pattern[i + 1] !== "]")
|
|
222
|
+
current += pattern[++i];
|
|
223
|
+
i++;
|
|
224
|
+
template.push({ type: "literal", content: current || "[" });
|
|
225
|
+
} else {
|
|
226
|
+
current += currentChar;
|
|
227
|
+
while (i + 1 < pattern.length && !tokens.has(pattern[i + 1]) && pattern[i + 1] !== "[")
|
|
228
|
+
current += pattern[++i];
|
|
229
|
+
template.push({ type: "literal", content: current });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return template;
|
|
233
|
+
}
|
|
234
|
+
static resolveDate(time) {
|
|
235
|
+
return time instanceof Date ? time : new Date(time);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
__name(Timestamp, "Timestamp");
|
|
239
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
240
|
+
0 && (module.exports = {
|
|
241
|
+
Time,
|
|
242
|
+
Timestamp,
|
|
243
|
+
days,
|
|
244
|
+
months,
|
|
245
|
+
tokens
|
|
246
|
+
});
|
|
247
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/lib/constants.ts","../src/lib/Timestamp.ts"],"sourcesContent":["export * from './lib/constants';\nexport * from './lib/Timestamp';\n","export enum Time {\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = 1000 * 60,\n\tHour = 1000 * 60 * 60,\n\tDay = 1000 * 60 * 60 * 24,\n\tMonth = 1000 * 60 * 60 * 24 * (365 / 12),\n\tYear = 1000 * 60 * 60 * 24 * 365\n}\n\nexport const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\n\nexport const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n\nexport const tokens = new Map<string, number>([\n\t['Y', 4],\n\t['Q', 1],\n\t['M', 4],\n\t['D', 4],\n\t['d', 4],\n\t['X', 1],\n\t['x', 1],\n\t['H', 2],\n\t['h', 2],\n\t['a', 1],\n\t['A', 1],\n\t['m', 2],\n\t['s', 2],\n\t['S', 3],\n\t['Z', 2],\n\t['l', 4],\n\t['L', 4],\n\t['T', 1],\n\t['t', 1]\n]);\n","import { days, months, Time, tokens } from './constants';\n\ninterface TokenResolver {\n\t(time: Date): string;\n}\n\nconst tokenResolvers = new Map<string, TokenResolver>([\n\t// Dates\n\t['Y', (time) => String(time.getFullYear()).slice(2)],\n\t['YY', (time) => String(time.getFullYear()).slice(2)],\n\t['YYY', (time) => String(time.getFullYear())],\n\t['YYYY', (time) => String(time.getFullYear())],\n\t['Q', (time) => String((time.getMonth() + 1) / 3)],\n\t['M', (time) => String(time.getMonth() + 1)],\n\t['MM', (time) => String(time.getMonth() + 1).padStart(2, '0')],\n\t['MMM', (time) => months[time.getMonth()]],\n\t['MMMM', (time) => months[time.getMonth()]],\n\t['D', (time) => String(time.getDate())],\n\t['DD', (time) => String(time.getDate()).padStart(2, '0')],\n\t['DDD', (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / Time.Day))],\n\t['DDDD', (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / Time.Day))],\n\t[\n\t\t'd',\n\t\t(time) => {\n\t\t\tconst day = String(time.getDate());\n\t\t\tif (day !== '11' && day.endsWith('1')) return `${day}st`;\n\t\t\tif (day !== '12' && day.endsWith('2')) return `${day}nd`;\n\t\t\tif (day !== '13' && day.endsWith('3')) return `${day}rd`;\n\t\t\treturn `${day}th`;\n\t\t}\n\t],\n\t['dd', (time) => days[time.getDay()].slice(0, 2)],\n\t['ddd', (time) => days[time.getDay()].slice(0, 3)],\n\t['dddd', (time) => days[time.getDay()]],\n\t['X', (time) => String(time.valueOf() / Time.Second)],\n\t['x', (time) => String(time.valueOf())],\n\n\t// Locales\n\t['H', (time) => String(time.getHours())],\n\t['HH', (time) => String(time.getHours()).padStart(2, '0')],\n\t['h', (time) => String(time.getHours() % 12 || 12)],\n\t['hh', (time) => String(time.getHours() % 12 || 12).padStart(2, '0')],\n\t['a', (time) => (time.getHours() < 12 ? 'am' : 'pm')],\n\t['A', (time) => (time.getHours() < 12 ? 'AM' : 'PM')],\n\t['m', (time) => String(time.getMinutes())],\n\t['mm', (time) => String(time.getMinutes()).padStart(2, '0')],\n\t['s', (time) => String(time.getSeconds())],\n\t['ss', (time) => String(time.getSeconds()).padStart(2, '0')],\n\t['S', (time) => String(time.getMilliseconds())],\n\t['SS', (time) => String(time.getMilliseconds()).padStart(2, '0')],\n\t['SSS', (time) => String(time.getMilliseconds()).padStart(3, '0')],\n\t['T', (time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`],\n\t[\n\t\t't',\n\t\t(time) =>\n\t\t\t`${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')}:${String(time.getSeconds()).padStart(2, '0')} ${\n\t\t\t\ttime.getHours() < 12 ? 'am' : 'pm'\n\t\t\t}`\n\t],\n\t['L', (time) => `${String(time.getMonth() + 1).padStart(2, '0')}/${String(time.getDate()).padStart(2, '0')}/${String(time.getFullYear())}`],\n\t['l', (time) => `${String(time.getMonth() + 1)}/${String(time.getDate()).padStart(2, '0')}/${String(time.getFullYear())}`],\n\t['LL', (time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())}`],\n\t['ll', (time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())}`],\n\t[\n\t\t'LLL',\n\t\t(time) =>\n\t\t\t`${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'lll',\n\t\t(time) =>\n\t\t\t`${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'LLLL',\n\t\t(time) =>\n\t\t\t`${days[time.getDay()]}, ${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'llll',\n\t\t(time) =>\n\t\t\t`${days[time.getDay()].slice(0, 3)} ${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(\n\t\t\t\ttime.getFullYear()\n\t\t\t)} ${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'Z',\n\t\t(time) => {\n\t\t\tconst offset = time.getTimezoneOffset();\n\t\t\tconst unsigned = offset >= 0;\n\t\t\tconst absolute = Math.abs(offset);\n\t\t\t/* istanbul ignore next: whether it's signed or unsigned, depends on where the machine is, I cannot control this. */\n\t\t\treturn `${unsigned ? '+' : '-'}${String(Math.floor(absolute / 60)).padStart(2, '0')}:${String(absolute % 60).padStart(2, '0')}`;\n\t\t}\n\t],\n\t[\n\t\t'ZZ',\n\t\t(time) => {\n\t\t\tconst offset = time.getTimezoneOffset();\n\t\t\tconst unsigned = offset >= 0;\n\t\t\tconst absolute = Math.abs(offset);\n\t\t\t/* istanbul ignore next: whether it's signed or unsigned, depends on where the machine is, I cannot control this. */\n\t\t\treturn `${unsigned ? '+' : '-'}${String(Math.floor(absolute / 60)).padStart(2, '0')}:${String(absolute % 60).padStart(2, '0')}`;\n\t\t}\n\t]\n]);\n/* eslint-enable max-len */\n\nexport type TimeResolvable = Date | number | string;\n\nexport interface TimestampTemplateEntry {\n\ttype: string;\n\tcontent: string | null;\n}\n\n/**\n * Timestamp class, parses the pattern once, displays the desired Date or UNIX timestamp with the selected pattern.\n */\nexport class Timestamp {\n\t/**\n\t * The raw pattern\n\t * @since 1.0.0\n\t */\n\tpublic pattern: string;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate template: TimestampTemplateEntry[];\n\n\t/**\n\t * Starts a new Timestamp and parses the pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t */\n\tpublic constructor(pattern: string) {\n\t\tthis.pattern = pattern;\n\t\tthis.template = Timestamp.parse(pattern);\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param time The time to display\n\t */\n\tpublic display(time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(this.template, time);\n\t}\n\n\t/**\n\t * Display the current date utc with the current pattern.\n\t * @since 1.0.0\n\t * @param time The time to display in utc\n\t */\n\tpublic displayUTC(time?: TimeResolvable): string {\n\t\treturn Timestamp.display(this.template, Timestamp.utc(time));\n\t}\n\n\t/**\n\t * Edits the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The new pattern for this instance\n\t * @chainable\n\t */\n\tpublic edit(pattern: string): this {\n\t\tthis.pattern = pattern;\n\t\tthis.template = Timestamp.parse(pattern);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Defines the toString behavior of Timestamp.\n\t */\n\tpublic toString(): string {\n\t\treturn this.display();\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t * @param time The time to display\n\t */\n\tpublic static displayArbitrary(pattern: string, time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(Timestamp.parse(pattern), time);\n\t}\n\n\t/**\n\t * Display the current date utc with the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t * @param time The time to display\n\t */\n\tpublic static displayUTCArbitrary(pattern: string, time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(Timestamp.parse(pattern), Timestamp.utc(time));\n\t}\n\n\t/**\n\t * Creates a UTC Date object to work with.\n\t * @since 1.0.0\n\t * @param time The date to convert to utc\n\t */\n\tpublic static utc(time: Date | number | string = new Date()): Date {\n\t\ttime = Timestamp.resolveDate(time);\n\t\treturn new Date(time.valueOf() + time.getTimezoneOffset() * 60000);\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param template The pattern to parse\n\t * @param time The time to display\n\t */\n\tprivate static display(template: TimestampTemplateEntry[], time: Date | number | string): string {\n\t\tlet output = '';\n\t\tconst parsedTime = Timestamp.resolveDate(time);\n\t\tfor (const { content, type } of template) output += content || tokenResolvers.get(type)!(parsedTime);\n\t\treturn output;\n\t}\n\n\t/**\n\t * Parses the pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t */\n\tprivate static parse(pattern: string): TimestampTemplateEntry[] {\n\t\tconst template: TimestampTemplateEntry[] = [];\n\t\tfor (let i = 0; i < pattern.length; i++) {\n\t\t\tlet current = '';\n\t\t\tconst currentChar = pattern[i];\n\t\t\tconst tokenMax = tokens.get(currentChar);\n\t\t\tif (typeof tokenMax === 'number') {\n\t\t\t\tcurrent += currentChar;\n\t\t\t\twhile (pattern[i + 1] === currentChar && current.length < tokenMax) current += pattern[++i];\n\t\t\t\ttemplate.push({ type: current, content: null });\n\t\t\t} else if (currentChar === '[') {\n\t\t\t\twhile (i + 1 < pattern.length && pattern[i + 1] !== ']') current += pattern[++i];\n\t\t\t\ti++;\n\t\t\t\ttemplate.push({ type: 'literal', content: current || '[' });\n\t\t\t} else {\n\t\t\t\tcurrent += currentChar;\n\t\t\t\twhile (i + 1 < pattern.length && !tokens.has(pattern[i + 1]) && pattern[i + 1] !== '[') current += pattern[++i];\n\t\t\t\ttemplate.push({ type: 'literal', content: current });\n\t\t\t}\n\t\t}\n\n\t\treturn template;\n\t}\n\n\t/**\n\t * Resolves a date.\n\t * @since 1.0.0\n\t * @param time The time to parse\n\t */\n\tprivate static resolveDate(time: TimeResolvable): Date {\n\t\treturn time instanceof Date ? time : new Date(time);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAK,OAAL,kBAAKA,UAAL;AACN,EAAAA,YAAA,iBAAc,KAAd;AACA,EAAAA,YAAA,YAAS,OAAT;AACA,EAAAA,YAAA,YAAS,OAAT;AACA,EAAAA,YAAA,UAAO,QAAP;AACA,EAAAA,YAAA,SAAM,SAAN;AACA,EAAAA,YAAA,WAAQ,UAAR;AACA,EAAAA,YAAA,UAAO,WAAP;AAPW,SAAAA;AAAA,GAAA;AAUL,IAAM,OAAO,CAAC,UAAU,UAAU,WAAW,aAAa,YAAY,UAAU,UAAU;AAE1F,IAAM,SAAS,CAAC,WAAW,YAAY,SAAS,SAAS,OAAO,QAAQ,QAAQ,UAAU,aAAa,WAAW,YAAY,UAAU;AAExI,IAAM,SAAS,oBAAI,IAAoB;AAAA,EAC7C,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,EACP,CAAC,KAAK,CAAC;AAAA,E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AO,IAAI,WAAW;AACvC,UAAI,OAAO,aAAa,UAAU;AACjC,mBAAW;AACX,eAAO,QAAQ,IAAI,OAAO,eAAe,QAAQ,SAAS;AAAU,qBAAW,QAAQ,EAAE;AACzF,iBAAS,KAAK,EAAE,MAAM,SAAS,SAAS,KAAK,CAAC;AAAA,MAC/C,WAAW,gBAAgB,KAAK;AAC/B,eAAO,IAAI,IAAI,QAAQ,UAAU,QAAQ,IAAI,OAAO;AAAK,qBAAW,QAAQ,EAAE;AAC9E;AACA,iBAAS,KAAK,EAAE,MAAM,WAAW,SAAS,WAAW,IAAI,CAAC;AAAA,MAC3D,OAAO;AACN,mBAAW;AACX,eAAO,IAAI,IAAI,QAAQ,UAAU,CAAC,OAAO,IAAI,QAAQ,IAAI,EAAE,KAAK,QAAQ,IAAI,OAAO;AAAK,qBAAW,QAAQ,EAAE;AAC7G,iBAAS,KAAK,EAAE,MAAM,WAAW,SAAS,QAAQ,CAAC;AAAA,MACpD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAOA,OAAe,YAAY,MAA4B;AACtD,WAAO,gBAAgB,OAAO,OAAO,IAAI,KAAK,IAAI;AAAA,EACnD;AACD;AA3Ia;","names":["Time"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => {
|
|
5
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
|
+
return value;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/lib/constants.ts
|
|
10
|
+
var Time = /* @__PURE__ */ ((Time2) => {
|
|
11
|
+
Time2[Time2["Millisecond"] = 1] = "Millisecond";
|
|
12
|
+
Time2[Time2["Second"] = 1e3] = "Second";
|
|
13
|
+
Time2[Time2["Minute"] = 6e4] = "Minute";
|
|
14
|
+
Time2[Time2["Hour"] = 36e5] = "Hour";
|
|
15
|
+
Time2[Time2["Day"] = 864e5] = "Day";
|
|
16
|
+
Time2[Time2["Month"] = 2628e6] = "Month";
|
|
17
|
+
Time2[Time2["Year"] = 31536e6] = "Year";
|
|
18
|
+
return Time2;
|
|
19
|
+
})(Time || {});
|
|
20
|
+
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
21
|
+
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
|
|
22
|
+
var tokens = /* @__PURE__ */ new Map([
|
|
23
|
+
["Y", 4],
|
|
24
|
+
["Q", 1],
|
|
25
|
+
["M", 4],
|
|
26
|
+
["D", 4],
|
|
27
|
+
["d", 4],
|
|
28
|
+
["X", 1],
|
|
29
|
+
["x", 1],
|
|
30
|
+
["H", 2],
|
|
31
|
+
["h", 2],
|
|
32
|
+
["a", 1],
|
|
33
|
+
["A", 1],
|
|
34
|
+
["m", 2],
|
|
35
|
+
["s", 2],
|
|
36
|
+
["S", 3],
|
|
37
|
+
["Z", 2],
|
|
38
|
+
["l", 4],
|
|
39
|
+
["L", 4],
|
|
40
|
+
["T", 1],
|
|
41
|
+
["t", 1]
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
// src/lib/Timestamp.ts
|
|
45
|
+
var tokenResolvers = /* @__PURE__ */ new Map([
|
|
46
|
+
["Y", (time) => String(time.getFullYear()).slice(2)],
|
|
47
|
+
["YY", (time) => String(time.getFullYear()).slice(2)],
|
|
48
|
+
["YYY", (time) => String(time.getFullYear())],
|
|
49
|
+
["YYYY", (time) => String(time.getFullYear())],
|
|
50
|
+
["Q", (time) => String((time.getMonth() + 1) / 3)],
|
|
51
|
+
["M", (time) => String(time.getMonth() + 1)],
|
|
52
|
+
["MM", (time) => String(time.getMonth() + 1).padStart(2, "0")],
|
|
53
|
+
["MMM", (time) => months[time.getMonth()]],
|
|
54
|
+
["MMMM", (time) => months[time.getMonth()]],
|
|
55
|
+
["D", (time) => String(time.getDate())],
|
|
56
|
+
["DD", (time) => String(time.getDate()).padStart(2, "0")],
|
|
57
|
+
["DDD", (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / 864e5 /* Day */))],
|
|
58
|
+
["DDDD", (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / 864e5 /* Day */))],
|
|
59
|
+
[
|
|
60
|
+
"d",
|
|
61
|
+
(time) => {
|
|
62
|
+
const day = String(time.getDate());
|
|
63
|
+
if (day !== "11" && day.endsWith("1"))
|
|
64
|
+
return `${day}st`;
|
|
65
|
+
if (day !== "12" && day.endsWith("2"))
|
|
66
|
+
return `${day}nd`;
|
|
67
|
+
if (day !== "13" && day.endsWith("3"))
|
|
68
|
+
return `${day}rd`;
|
|
69
|
+
return `${day}th`;
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
["dd", (time) => days[time.getDay()].slice(0, 2)],
|
|
73
|
+
["ddd", (time) => days[time.getDay()].slice(0, 3)],
|
|
74
|
+
["dddd", (time) => days[time.getDay()]],
|
|
75
|
+
["X", (time) => String(time.valueOf() / 1e3 /* Second */)],
|
|
76
|
+
["x", (time) => String(time.valueOf())],
|
|
77
|
+
["H", (time) => String(time.getHours())],
|
|
78
|
+
["HH", (time) => String(time.getHours()).padStart(2, "0")],
|
|
79
|
+
["h", (time) => String(time.getHours() % 12 || 12)],
|
|
80
|
+
["hh", (time) => String(time.getHours() % 12 || 12).padStart(2, "0")],
|
|
81
|
+
["a", (time) => time.getHours() < 12 ? "am" : "pm"],
|
|
82
|
+
["A", (time) => time.getHours() < 12 ? "AM" : "PM"],
|
|
83
|
+
["m", (time) => String(time.getMinutes())],
|
|
84
|
+
["mm", (time) => String(time.getMinutes()).padStart(2, "0")],
|
|
85
|
+
["s", (time) => String(time.getSeconds())],
|
|
86
|
+
["ss", (time) => String(time.getSeconds()).padStart(2, "0")],
|
|
87
|
+
["S", (time) => String(time.getMilliseconds())],
|
|
88
|
+
["SS", (time) => String(time.getMilliseconds()).padStart(2, "0")],
|
|
89
|
+
["SSS", (time) => String(time.getMilliseconds()).padStart(3, "0")],
|
|
90
|
+
["T", (time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`],
|
|
91
|
+
[
|
|
92
|
+
"t",
|
|
93
|
+
(time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")}:${String(time.getSeconds()).padStart(2, "0")} ${time.getHours() < 12 ? "am" : "pm"}`
|
|
94
|
+
],
|
|
95
|
+
["L", (time) => `${String(time.getMonth() + 1).padStart(2, "0")}/${String(time.getDate()).padStart(2, "0")}/${String(time.getFullYear())}`],
|
|
96
|
+
["l", (time) => `${String(time.getMonth() + 1)}/${String(time.getDate()).padStart(2, "0")}/${String(time.getFullYear())}`],
|
|
97
|
+
["LL", (time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())}`],
|
|
98
|
+
["ll", (time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())}`],
|
|
99
|
+
[
|
|
100
|
+
"LLL",
|
|
101
|
+
(time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
102
|
+
time.getHours() % 12 || 12
|
|
103
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"lll",
|
|
107
|
+
(time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
108
|
+
time.getHours() % 12 || 12
|
|
109
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"LLLL",
|
|
113
|
+
(time) => `${days[time.getDay()]}, ${months[time.getMonth()]} ${String(time.getDate()).padStart(2, "0")}, ${String(time.getFullYear())} ${String(
|
|
114
|
+
time.getHours() % 12 || 12
|
|
115
|
+
)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"llll",
|
|
119
|
+
(time) => `${days[time.getDay()].slice(0, 3)} ${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, "0")}, ${String(
|
|
120
|
+
time.getFullYear()
|
|
121
|
+
)} ${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, "0")} ${time.getHours() < 12 ? "AM" : "PM"}`
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
"Z",
|
|
125
|
+
(time) => {
|
|
126
|
+
const offset = time.getTimezoneOffset();
|
|
127
|
+
const unsigned = offset >= 0;
|
|
128
|
+
const absolute = Math.abs(offset);
|
|
129
|
+
return `${unsigned ? "+" : "-"}${String(Math.floor(absolute / 60)).padStart(2, "0")}:${String(absolute % 60).padStart(2, "0")}`;
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
[
|
|
133
|
+
"ZZ",
|
|
134
|
+
(time) => {
|
|
135
|
+
const offset = time.getTimezoneOffset();
|
|
136
|
+
const unsigned = offset >= 0;
|
|
137
|
+
const absolute = Math.abs(offset);
|
|
138
|
+
return `${unsigned ? "+" : "-"}${String(Math.floor(absolute / 60)).padStart(2, "0")}:${String(absolute % 60).padStart(2, "0")}`;
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
]);
|
|
142
|
+
var Timestamp = class {
|
|
143
|
+
constructor(pattern) {
|
|
144
|
+
__publicField(this, "pattern");
|
|
145
|
+
__publicField(this, "template");
|
|
146
|
+
this.pattern = pattern;
|
|
147
|
+
this.template = Timestamp.parse(pattern);
|
|
148
|
+
}
|
|
149
|
+
display(time = new Date()) {
|
|
150
|
+
return Timestamp.display(this.template, time);
|
|
151
|
+
}
|
|
152
|
+
displayUTC(time) {
|
|
153
|
+
return Timestamp.display(this.template, Timestamp.utc(time));
|
|
154
|
+
}
|
|
155
|
+
edit(pattern) {
|
|
156
|
+
this.pattern = pattern;
|
|
157
|
+
this.template = Timestamp.parse(pattern);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
toString() {
|
|
161
|
+
return this.display();
|
|
162
|
+
}
|
|
163
|
+
static displayArbitrary(pattern, time = new Date()) {
|
|
164
|
+
return Timestamp.display(Timestamp.parse(pattern), time);
|
|
165
|
+
}
|
|
166
|
+
static displayUTCArbitrary(pattern, time = new Date()) {
|
|
167
|
+
return Timestamp.display(Timestamp.parse(pattern), Timestamp.utc(time));
|
|
168
|
+
}
|
|
169
|
+
static utc(time = new Date()) {
|
|
170
|
+
time = Timestamp.resolveDate(time);
|
|
171
|
+
return new Date(time.valueOf() + time.getTimezoneOffset() * 6e4);
|
|
172
|
+
}
|
|
173
|
+
static display(template, time) {
|
|
174
|
+
let output = "";
|
|
175
|
+
const parsedTime = Timestamp.resolveDate(time);
|
|
176
|
+
for (const { content, type } of template)
|
|
177
|
+
output += content || tokenResolvers.get(type)(parsedTime);
|
|
178
|
+
return output;
|
|
179
|
+
}
|
|
180
|
+
static parse(pattern) {
|
|
181
|
+
const template = [];
|
|
182
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
183
|
+
let current = "";
|
|
184
|
+
const currentChar = pattern[i];
|
|
185
|
+
const tokenMax = tokens.get(currentChar);
|
|
186
|
+
if (typeof tokenMax === "number") {
|
|
187
|
+
current += currentChar;
|
|
188
|
+
while (pattern[i + 1] === currentChar && current.length < tokenMax)
|
|
189
|
+
current += pattern[++i];
|
|
190
|
+
template.push({ type: current, content: null });
|
|
191
|
+
} else if (currentChar === "[") {
|
|
192
|
+
while (i + 1 < pattern.length && pattern[i + 1] !== "]")
|
|
193
|
+
current += pattern[++i];
|
|
194
|
+
i++;
|
|
195
|
+
template.push({ type: "literal", content: current || "[" });
|
|
196
|
+
} else {
|
|
197
|
+
current += currentChar;
|
|
198
|
+
while (i + 1 < pattern.length && !tokens.has(pattern[i + 1]) && pattern[i + 1] !== "[")
|
|
199
|
+
current += pattern[++i];
|
|
200
|
+
template.push({ type: "literal", content: current });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return template;
|
|
204
|
+
}
|
|
205
|
+
static resolveDate(time) {
|
|
206
|
+
return time instanceof Date ? time : new Date(time);
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
__name(Timestamp, "Timestamp");
|
|
210
|
+
export {
|
|
211
|
+
Time,
|
|
212
|
+
Timestamp,
|
|
213
|
+
days,
|
|
214
|
+
months,
|
|
215
|
+
tokens
|
|
216
|
+
};
|
|
217
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/constants.ts","../src/lib/Timestamp.ts"],"sourcesContent":["export enum Time {\n\tMillisecond = 1,\n\tSecond = 1000,\n\tMinute = 1000 * 60,\n\tHour = 1000 * 60 * 60,\n\tDay = 1000 * 60 * 60 * 24,\n\tMonth = 1000 * 60 * 60 * 24 * (365 / 12),\n\tYear = 1000 * 60 * 60 * 24 * 365\n}\n\nexport const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\n\nexport const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];\n\nexport const tokens = new Map<string, number>([\n\t['Y', 4],\n\t['Q', 1],\n\t['M', 4],\n\t['D', 4],\n\t['d', 4],\n\t['X', 1],\n\t['x', 1],\n\t['H', 2],\n\t['h', 2],\n\t['a', 1],\n\t['A', 1],\n\t['m', 2],\n\t['s', 2],\n\t['S', 3],\n\t['Z', 2],\n\t['l', 4],\n\t['L', 4],\n\t['T', 1],\n\t['t', 1]\n]);\n","import { days, months, Time, tokens } from './constants';\n\ninterface TokenResolver {\n\t(time: Date): string;\n}\n\nconst tokenResolvers = new Map<string, TokenResolver>([\n\t// Dates\n\t['Y', (time) => String(time.getFullYear()).slice(2)],\n\t['YY', (time) => String(time.getFullYear()).slice(2)],\n\t['YYY', (time) => String(time.getFullYear())],\n\t['YYYY', (time) => String(time.getFullYear())],\n\t['Q', (time) => String((time.getMonth() + 1) / 3)],\n\t['M', (time) => String(time.getMonth() + 1)],\n\t['MM', (time) => String(time.getMonth() + 1).padStart(2, '0')],\n\t['MMM', (time) => months[time.getMonth()]],\n\t['MMMM', (time) => months[time.getMonth()]],\n\t['D', (time) => String(time.getDate())],\n\t['DD', (time) => String(time.getDate()).padStart(2, '0')],\n\t['DDD', (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / Time.Day))],\n\t['DDDD', (time) => String(Math.floor((time.getTime() - new Date(time.getFullYear(), 0, 0).getTime()) / Time.Day))],\n\t[\n\t\t'd',\n\t\t(time) => {\n\t\t\tconst day = String(time.getDate());\n\t\t\tif (day !== '11' && day.endsWith('1')) return `${day}st`;\n\t\t\tif (day !== '12' && day.endsWith('2')) return `${day}nd`;\n\t\t\tif (day !== '13' && day.endsWith('3')) return `${day}rd`;\n\t\t\treturn `${day}th`;\n\t\t}\n\t],\n\t['dd', (time) => days[time.getDay()].slice(0, 2)],\n\t['ddd', (time) => days[time.getDay()].slice(0, 3)],\n\t['dddd', (time) => days[time.getDay()]],\n\t['X', (time) => String(time.valueOf() / Time.Second)],\n\t['x', (time) => String(time.valueOf())],\n\n\t// Locales\n\t['H', (time) => String(time.getHours())],\n\t['HH', (time) => String(time.getHours()).padStart(2, '0')],\n\t['h', (time) => String(time.getHours() % 12 || 12)],\n\t['hh', (time) => String(time.getHours() % 12 || 12).padStart(2, '0')],\n\t['a', (time) => (time.getHours() < 12 ? 'am' : 'pm')],\n\t['A', (time) => (time.getHours() < 12 ? 'AM' : 'PM')],\n\t['m', (time) => String(time.getMinutes())],\n\t['mm', (time) => String(time.getMinutes()).padStart(2, '0')],\n\t['s', (time) => String(time.getSeconds())],\n\t['ss', (time) => String(time.getSeconds()).padStart(2, '0')],\n\t['S', (time) => String(time.getMilliseconds())],\n\t['SS', (time) => String(time.getMilliseconds()).padStart(2, '0')],\n\t['SSS', (time) => String(time.getMilliseconds()).padStart(3, '0')],\n\t['T', (time) => `${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`],\n\t[\n\t\t't',\n\t\t(time) =>\n\t\t\t`${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')}:${String(time.getSeconds()).padStart(2, '0')} ${\n\t\t\t\ttime.getHours() < 12 ? 'am' : 'pm'\n\t\t\t}`\n\t],\n\t['L', (time) => `${String(time.getMonth() + 1).padStart(2, '0')}/${String(time.getDate()).padStart(2, '0')}/${String(time.getFullYear())}`],\n\t['l', (time) => `${String(time.getMonth() + 1)}/${String(time.getDate()).padStart(2, '0')}/${String(time.getFullYear())}`],\n\t['LL', (time) => `${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())}`],\n\t['ll', (time) => `${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())}`],\n\t[\n\t\t'LLL',\n\t\t(time) =>\n\t\t\t`${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'lll',\n\t\t(time) =>\n\t\t\t`${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'LLLL',\n\t\t(time) =>\n\t\t\t`${days[time.getDay()]}, ${months[time.getMonth()]} ${String(time.getDate()).padStart(2, '0')}, ${String(time.getFullYear())} ${String(\n\t\t\t\ttime.getHours() % 12 || 12\n\t\t\t)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'llll',\n\t\t(time) =>\n\t\t\t`${days[time.getDay()].slice(0, 3)} ${months[time.getMonth()].slice(0, 3)} ${String(time.getDate()).padStart(2, '0')}, ${String(\n\t\t\t\ttime.getFullYear()\n\t\t\t)} ${String(time.getHours() % 12 || 12)}:${String(time.getMinutes()).padStart(2, '0')} ${time.getHours() < 12 ? 'AM' : 'PM'}`\n\t],\n\t[\n\t\t'Z',\n\t\t(time) => {\n\t\t\tconst offset = time.getTimezoneOffset();\n\t\t\tconst unsigned = offset >= 0;\n\t\t\tconst absolute = Math.abs(offset);\n\t\t\t/* istanbul ignore next: whether it's signed or unsigned, depends on where the machine is, I cannot control this. */\n\t\t\treturn `${unsigned ? '+' : '-'}${String(Math.floor(absolute / 60)).padStart(2, '0')}:${String(absolute % 60).padStart(2, '0')}`;\n\t\t}\n\t],\n\t[\n\t\t'ZZ',\n\t\t(time) => {\n\t\t\tconst offset = time.getTimezoneOffset();\n\t\t\tconst unsigned = offset >= 0;\n\t\t\tconst absolute = Math.abs(offset);\n\t\t\t/* istanbul ignore next: whether it's signed or unsigned, depends on where the machine is, I cannot control this. */\n\t\t\treturn `${unsigned ? '+' : '-'}${String(Math.floor(absolute / 60)).padStart(2, '0')}:${String(absolute % 60).padStart(2, '0')}`;\n\t\t}\n\t]\n]);\n/* eslint-enable max-len */\n\nexport type TimeResolvable = Date | number | string;\n\nexport interface TimestampTemplateEntry {\n\ttype: string;\n\tcontent: string | null;\n}\n\n/**\n * Timestamp class, parses the pattern once, displays the desired Date or UNIX timestamp with the selected pattern.\n */\nexport class Timestamp {\n\t/**\n\t * The raw pattern\n\t * @since 1.0.0\n\t */\n\tpublic pattern: string;\n\n\t/**\n\t * @since 1.0.0\n\t */\n\tprivate template: TimestampTemplateEntry[];\n\n\t/**\n\t * Starts a new Timestamp and parses the pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t */\n\tpublic constructor(pattern: string) {\n\t\tthis.pattern = pattern;\n\t\tthis.template = Timestamp.parse(pattern);\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param time The time to display\n\t */\n\tpublic display(time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(this.template, time);\n\t}\n\n\t/**\n\t * Display the current date utc with the current pattern.\n\t * @since 1.0.0\n\t * @param time The time to display in utc\n\t */\n\tpublic displayUTC(time?: TimeResolvable): string {\n\t\treturn Timestamp.display(this.template, Timestamp.utc(time));\n\t}\n\n\t/**\n\t * Edits the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The new pattern for this instance\n\t * @chainable\n\t */\n\tpublic edit(pattern: string): this {\n\t\tthis.pattern = pattern;\n\t\tthis.template = Timestamp.parse(pattern);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Defines the toString behavior of Timestamp.\n\t */\n\tpublic toString(): string {\n\t\treturn this.display();\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t * @param time The time to display\n\t */\n\tpublic static displayArbitrary(pattern: string, time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(Timestamp.parse(pattern), time);\n\t}\n\n\t/**\n\t * Display the current date utc with the current pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t * @param time The time to display\n\t */\n\tpublic static displayUTCArbitrary(pattern: string, time: TimeResolvable = new Date()): string {\n\t\treturn Timestamp.display(Timestamp.parse(pattern), Timestamp.utc(time));\n\t}\n\n\t/**\n\t * Creates a UTC Date object to work with.\n\t * @since 1.0.0\n\t * @param time The date to convert to utc\n\t */\n\tpublic static utc(time: Date | number | string = new Date()): Date {\n\t\ttime = Timestamp.resolveDate(time);\n\t\treturn new Date(time.valueOf() + time.getTimezoneOffset() * 60000);\n\t}\n\n\t/**\n\t * Display the current date with the current pattern.\n\t * @since 1.0.0\n\t * @param template The pattern to parse\n\t * @param time The time to display\n\t */\n\tprivate static display(template: TimestampTemplateEntry[], time: Date | number | string): string {\n\t\tlet output = '';\n\t\tconst parsedTime = Timestamp.resolveDate(time);\n\t\tfor (const { content, type } of template) output += content || tokenResolvers.get(type)!(parsedTime);\n\t\treturn output;\n\t}\n\n\t/**\n\t * Parses the pattern.\n\t * @since 1.0.0\n\t * @param pattern The pattern to parse\n\t */\n\tprivate static parse(pattern: string): TimestampTemplateEntry[] {\n\t\tconst template: TimestampTemplateEntry[] = [];\n\t\tfor (let i = 0; i < pattern.length; i++) {\n\t\t\tlet current = '';\n\t\t\tconst currentChar = pattern[i];\n\t\t\tconst tokenMax = tokens.get(currentChar);\n\t\t\tif (typeof tokenMax === 'number') {\n\t\t\t\tcurrent += currentChar;\n\t\t\t\twhile (pattern[i + 1] === currentChar && current.length < tokenMax) current += pattern[++i];\n\t\t\t\ttemplate.push({ type: current, content: null });\n\t\t\t} else if (currentChar === '[') {\n\t\t\t\twhile (i + 1 < pattern.length && pattern[i + 1] !== ']') current += pattern[++i];\n\t\t\t\ti++;\n\t\t\t\ttemplate.push({ type: 'literal', content: current || '[' });\n\t\t\t} else {\n\t\t\t\tcurrent += currentChar;\n\t\t\t\twhile (i + 1 < pattern.length && !tokens.has(pattern[i + 1]) && pattern[i + 1] !== '[') current += pattern[++i];\n\t\t\t\ttemplate.push({ type: 'literal', content: current });\n\t\t\t}\n\t\t}\n\n\t\treturn template;\n\t}\n\n\t/**\n\t * Resolves a date.\n\t * @since 1.0.0\n\t * @param time The time to parse\n\t */\n\tprivate static resolveDate(time: Time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AK;AAC/B,eAAO,IAAI,IAAI,QAAQ,UAAU,QAAQ,IAAI,OAAO;AAAK,qBAAW,QAAQ,EAAE;AAC9E;AACA,iBAAS,KAAK,EAAE,MAAM,WAAW,SAAS,WAAW,IAAI,CAAC;AAAA,MAC3D,OAAO;AACN,mBAAW;AACX,eAAO,IAAI,IAAI,QAAQ,UAAU,CAAC,OAAO,IAAI,QAAQ,IAAI,EAAE,KAAK,QAAQ,IAAI,OAAO;AAAK,qBAAW,QAAQ,EAAE;AAC7G,iBAAS,KAAK,EAAE,MAAM,WAAW,SAAS,QAAQ,CAAC;AAAA,MACpD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EAOA,OAAe,YAAY,MAA4B;AACtD,WAAO,gBAAgB,OAAO,OAAO,IAAI,KAAK,IAAI;AAAA,EACnD;AACD;AA3Ia;","names":["Time"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sapphire/timestamp",
|
|
3
|
+
"version": "1.0.1-next.574299a.0",
|
|
4
|
+
"description": "A timestamp utility library for JavaScript.",
|
|
5
|
+
"author": "@sapphire",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.mjs",
|
|
9
|
+
"browser": "dist/index.global.js",
|
|
10
|
+
"unpkg": "dist/index.global.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"homepage": "https://github.com/sapphiredev/utilities/tree/main/packages/timestamp",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "vitest run",
|
|
21
|
+
"lint": "eslint src tests --ext ts --fix -c ../../.eslintrc",
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"docs": "typedoc-json-parser",
|
|
24
|
+
"prepack": "yarn build",
|
|
25
|
+
"bump": "cliff-jumper",
|
|
26
|
+
"check-update": "cliff-jumper --dry-run"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/sapphiredev/utilities.git",
|
|
31
|
+
"directory": "packages/timestamp"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist/**/*.js*",
|
|
35
|
+
"dist/**/*.mjs*",
|
|
36
|
+
"dist/**/*.d*"
|
|
37
|
+
],
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=v14.0.0",
|
|
40
|
+
"npm": ">=7.0.0"
|
|
41
|
+
},
|
|
42
|
+
"keywords": [
|
|
43
|
+
"@sapphire/timestamp",
|
|
44
|
+
"timestamp",
|
|
45
|
+
"bot",
|
|
46
|
+
"typescript",
|
|
47
|
+
"ts",
|
|
48
|
+
"yarn",
|
|
49
|
+
"discord",
|
|
50
|
+
"sapphire",
|
|
51
|
+
"standalone"
|
|
52
|
+
],
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/sapphiredev/utilities/issues"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@favware/cliff-jumper": "^1.8.7",
|
|
61
|
+
"@vitest/coverage-c8": "^0.23.4",
|
|
62
|
+
"tsup": "^6.2.3",
|
|
63
|
+
"typedoc": "^0.23.14",
|
|
64
|
+
"typedoc-json-parser": "^4.0.0",
|
|
65
|
+
"typescript": "^4.8.3",
|
|
66
|
+
"vitest": "^0.23.4"
|
|
67
|
+
}
|
|
68
|
+
}
|