From c5a2d778b6303d2b66e4a4506d3beb627dda45f4 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 9 Dec 2023 21:04:42 -0700 Subject: [PATCH] use padStart API --- background.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/background.js b/background.js index 5aff375..4274daf 100644 --- a/background.js +++ b/background.js @@ -57,18 +57,15 @@ function onAlarm (alarm) { chrome.alarms.onAlarm.addListener(onAlarm); -function date_prependZero (val) { - return val < 10 ? "0" + val : "" + val; -} - -// yyyy-m-d h:i:s -function date_format (d) { - var monthOneOffset = d.getMonth() + 1; // convert from 0-11 to 1-12 - - var formattedDate = d.getFullYear() + "-" + date_prependZero(monthOneOffset) + "-" + date_prependZero(d.getDate()) - + " " + date_prependZero(d.getHours()) + ":" + date_prependZero(d.getMinutes()) + ":" + date_prependZero(d.getSeconds()); - - return formattedDate; +// yyyy-mm-dd hh:mm:ss +function date_format(d) { + const prependZero = (val) => val.toString().padStart(2, '0'); + return d.getFullYear() + "-" + + prependZero(d.getMonth() + 1) + "-" + + prependZero(d.getDate()) + " " + + prependZero(d.getHours()) + ":" + + prependZero(d.getMinutes()) + ":" + + prependZero(d.getSeconds()); } -- 2.39.5