aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorKevin Hoerr <kjhoerr@protonmail.com>2022-12-28 12:12:02 -0500
committerGitHub <noreply@github.com>2022-12-28 12:12:02 -0500
commit1e698cdfa2f87dcea12c89de574c974f3f272ea7 (patch)
treedfca97aa344e85496847663131da1361901ed345 /src
parenteb6db55bfa1027f052efe6baee6af5f29fdd0ad9 (diff)
downloadsubmelon.dev-1e698cdfa2f87dcea12c89de574c974f3f272ea7.tar.gz
submelon.dev-1e698cdfa2f87dcea12c89de574c974f3f272ea7.tar.bz2
submelon.dev-1e698cdfa2f87dcea12c89de574c974f3f272ea7.zip
Use base-62 for timestamp (#52)
Diffstat (limited to 'src')
-rw-r--r--src/util/timestamp.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/util/timestamp.ts b/src/util/timestamp.ts
index f53f5ad..96c5064 100644
--- a/src/util/timestamp.ts
+++ b/src/util/timestamp.ts
@@ -19,6 +19,8 @@ const SHORT_CHARS =
* 48 = M
*
* 2022 = km (in base-62 this would be wC)
+ *
+ * @deprecated {@link encodeBase62} is now used to generate the timestamp instead
*/
export function toShort(valu: number): string {
return (
@@ -31,6 +33,21 @@ export function toShort(valu: number): string {
}
/**
+ * Encodes a number as a base-62 value string.
+ */
+export function encodeBase62(valu: number): string {
+ let res = "";
+ const mod = 62;
+
+ while (valu > 0) {
+ res = SHORT_CHARS[valu % mod] + res;
+ valu = Math.floor(valu / mod);
+ }
+
+ return res;
+}
+
+/**
* Translates a Unix EPOCH timestamp to a 62-char expression of the date. See
* the `toShort()` method for more details on the meaning of the final output.
*/
@@ -44,5 +61,5 @@ export function getTimestamp(seconds: number): string {
date.getUTCMinutes(),
];
- return dateArr.map(toShort).join(".") + "-0";
+ return dateArr.map(encodeBase62).join(".") + "-0";
}