From 61af4e35f62ed570507c2836d52b6eb5dc10f708 Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Thu, 6 Oct 2022 14:20:50 +0200 Subject: [PATCH] util.datetimeLocal --- util.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util.js b/util.js index e684a03..644382f 100644 --- a/util.js +++ b/util.js @@ -19,7 +19,10 @@ export const jsonDb = async file => { return db; }; +// date and time as UTC (no timezone offset) in nicely readable and sortable format, e.g., 2022-10-06 12:05:27.313 export const datetime = (d = new Date()) => d.toISOString().replace('T', ' ').replace('Z', ''); +// same as datetime() but for local timezone, e.g., UTC + 2h for the above in DE +export const datetimeLocal = (d = new Date()) => datetime(new Date(d.getTime() - new Date().getTimezoneOffset() * 60000)); export const filenamify = s => s.replaceAll(':', '.').replace(/[^a-z0-9 _\-.]/gi, '_'); // alternative: https://www.npmjs.com/package/filenamify - On Unix-like systems, / is reserved. On Windows, <>:"/\|?* along with trailing periods are reserved. // stealth with playwright: https://github.com/berstend/puppeteer-extra/issues/454#issuecomment-917437212