forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalver.ts
More file actions
37 lines (33 loc) 路 897 Bytes
/
Copy pathcalver.ts
File metadata and controls
37 lines (33 loc) 路 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
export class CalVer {
year: number;
month: number;
day: number;
micro?: number;
constructor(date: string) {
const [year, month, day, micro] = date.split(".").map((num) =>
Number.parseInt(num)
);
this.year = year;
this.month = month;
this.day = day;
this.micro = micro ?? undefined;
}
toString() {
return `${this.year}.${this.month.toString().padStart(2, "0")}.${
this.day.toString().padStart(2, "0")
}${this.micro ? "." + this.micro : ""}`;
}
incrementWith(date: Date) {
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const day = date.getUTCDate();
if (this.year === year && this.month === month && this.day === day) {
this.micro = (this.micro ?? 0) + 1;
} else {
this.year = year;
this.month = month;
this.day = day;
this.micro = undefined;
}
}
}