This repository was archived by the owner on Aug 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-28
lines changed
Expand file tree Collapse file tree 2 files changed +34
-28
lines changed Original file line number Diff line number Diff line change 1+ import units from "./units.js" ;
2+
13//#region Types
24
35/**
1315
1416//#endregion
1517
16- //#region Constants
17-
18- /** One minute in seconds. */
19- const ONE_MIN = 60 ;
20-
21- /** One hour in seconds. */
22- const ONE_HOUR = 60 * ONE_MIN ;
23-
24- /** One day in seconds. */
25- const ONE_DAY = 24 * ONE_HOUR ;
26-
27- /** One week in seconds. */
28- const ONE_WEEK = 7 * ONE_DAY ;
29-
30- /** One month in seconds. */
31- const ONE_MONTH = 4 * ONE_WEEK ;
32-
33- /** One year in seconds. */
34- const ONE_YEAR = 52 * ONE_WEEK ;
35-
36- //#endregion
37-
3818//#region Classes
3919
4020/** Represents the difference between two times. */
@@ -47,12 +27,12 @@ export class TimeDiff {
4727
4828 /** @type {Map<string, number> } */
4929 #units = new Map ( [
50- [ "year" , ONE_YEAR ] ,
51- [ "month" , ONE_MONTH ] ,
52- [ "week" , ONE_WEEK ] ,
53- [ "day" , ONE_DAY ] ,
54- [ "hour" , ONE_HOUR ] ,
55- [ "minute" , ONE_MIN ] ,
30+ [ "year" , units . year ] ,
31+ [ "month" , units . month ] ,
32+ [ "week" , units . week ] ,
33+ [ "day" , units . day ] ,
34+ [ "hour" , units . hour ] ,
35+ [ "minute" , units . minute ] ,
5636 ] ) ;
5737
5838 //#region Public API
Original file line number Diff line number Diff line change 1+ export default {
2+ /** One minute in seconds. */
3+ get minute ( ) {
4+ return 60 ;
5+ } ,
6+ /** One hour in seconds. */
7+ get hour ( ) {
8+ return this . minute * 60 ;
9+ } ,
10+ /** One day in seconds. */
11+ get day ( ) {
12+ return this . hour * 24 ;
13+ } ,
14+ /** One week in seconds. */
15+ get week ( ) {
16+ return this . day * 7 ;
17+ } ,
18+ /** One month in seconds. */
19+ get month ( ) {
20+ return this . week * 4 ;
21+ } ,
22+ /** One year in seconds. */
23+ get year ( ) {
24+ return this . day * 365 ;
25+ } ,
26+ } ;
You can’t perform that action at this time.
0 commit comments