Skip to content

Commit 9998f10

Browse files
authored
refactor: use human readable date for canary versions (#223)
1 parent 19a862c commit 9998f10

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/semver.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export async function bumpVersion(
6969
const suffix =
7070
typeof opts.suffix === "string"
7171
? `-${opts.suffix}`
72-
: `-${Math.round(Date.now() / 1000)}.${commits[0].shortHash}`;
72+
: `+${fmtDate(new Date())}-${commits[0].shortHash}`;
7373
pkg.version = config.newVersion = config.newVersion.split("-")[0] + suffix;
7474
}
7575

@@ -85,3 +85,14 @@ export async function bumpVersion(
8585

8686
return pkg.version;
8787
}
88+
89+
function fmtDate(d: Date): string {
90+
// YYMMDD-HHMMSS: 20240919-140954
91+
const date = joinNumbers([d.getFullYear(), d.getMonth() + 1, d.getDate()]);
92+
const time = joinNumbers([d.getHours(), d.getMinutes(), d.getSeconds()]);
93+
return `${date}-${time}`;
94+
}
95+
96+
function joinNumbers(items: number[]): string {
97+
return items.map((i) => (i + "").padStart(2, "0")).join("");
98+
}

0 commit comments

Comments
 (0)