From b40012973e8803c0d69632a588493198b77c440f Mon Sep 17 00:00:00 2001 From: Succubyss <87207237+Succubyss@users.noreply.github.com> Date: Wed, 24 Jul 2024 16:52:23 -0500 Subject: [PATCH] humanizedDateTime zero-pads month & day --- public/scripts/RossAscends-mods.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index 7723c8512..0f37650c4 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -157,18 +157,15 @@ export function shouldSendOnEnter() { //Does not break old characters/chats, as the code just uses whatever timestamp exists in the chat. //New chats made with characters will use this new formatting. export function humanizedDateTime() { - let baseDate = new Date(Date.now()); - let humanYear = baseDate.getFullYear(); - let humanMonth = baseDate.getMonth() + 1; - let humanDate = baseDate.getDate(); - let humanHour = (baseDate.getHours() < 10 ? '0' : '') + baseDate.getHours(); - let humanMinute = - (baseDate.getMinutes() < 10 ? '0' : '') + baseDate.getMinutes(); - let humanSecond = - (baseDate.getSeconds() < 10 ? '0' : '') + baseDate.getSeconds(); - let HumanizedDateTime = - humanYear + '-' + humanMonth + '-' + humanDate + '@' + humanHour + 'h' + humanMinute + 'm' + humanSecond + 's'; - return HumanizedDateTime; + const now = new Date(Date.now()); + const dt = { + year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate(), + hour: now.getHours(), minute: now.getMinutes(), second: now.getSeconds(), + } + for (const key in dt) { + dt[key] = dt[key].toString().padStart(2, '0'); + } + return `${dt.year}-${dt.month}-${dt.day}@${dt.hour}h${dt.minute}m${dt.second}s`; } //this is a common format version to display a timestamp on each chat message