From: Mike Frysinger Date: Sun, 10 Dec 2023 04:04:42 +0000 (-0700) Subject: use padStart API X-Git-Tag: v1.0~2 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=c5a2d778b6303d2b66e4a4506d3beb627dda45f4;p=chrome-ext%2Ftabs-backup.git use padStart API --- 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()); }