]> git.wh0rd.org Git - chrome-ext/tabs-backup.git/commitdiff
use padStart API
authorMike Frysinger <vapier@gentoo.org>
Sun, 10 Dec 2023 04:04:42 +0000 (21:04 -0700)
committerMike Frysinger <vapier@gentoo.org>
Sun, 10 Dec 2023 04:04:42 +0000 (21:04 -0700)
background.js

index 5aff375df3e747389f1a761198e7dd80d6ba882d..4274daf0d9213a3c21924d6ecbf5db4242bd787a 100644 (file)
@@ -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());
 }