From 9998f108c0120959adea152186534f89c2ab566c Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 19 Sep 2024 14:12:34 +0200 Subject: [PATCH] refactor: use human readable date for canary versions (#223) --- src/semver.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/semver.ts b/src/semver.ts index 3dcd561..49caab3 100644 --- a/src/semver.ts +++ b/src/semver.ts @@ -69,7 +69,7 @@ export async function bumpVersion( const suffix = typeof opts.suffix === "string" ? `-${opts.suffix}` - : `-${Math.round(Date.now() / 1000)}.${commits[0].shortHash}`; + : `+${fmtDate(new Date())}-${commits[0].shortHash}`; pkg.version = config.newVersion = config.newVersion.split("-")[0] + suffix; } @@ -85,3 +85,14 @@ export async function bumpVersion( return pkg.version; } + +function fmtDate(d: Date): string { + // YYMMDD-HHMMSS: 20240919-140954 + const date = joinNumbers([d.getFullYear(), d.getMonth() + 1, d.getDate()]); + const time = joinNumbers([d.getHours(), d.getMinutes(), d.getSeconds()]); + return `${date}-${time}`; +} + +function joinNumbers(items: number[]): string { + return items.map((i) => (i + "").padStart(2, "0")).join(""); +}