refactor(tree-wide): add & use calver implementation (#1534)
Co-authored-by: Hammy <[email protected]>
This commit is contained in:
1 parent
0a9cfae2c9
commit
fb505120bd
122 files changed
+272
-127
No files matched your search
@@ -0,0 +1,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user