From be8d138cd09c79fc7bb52b32a329dec1c671ab44 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 12 Jun 2019 08:39:58 +0000 Subject: [PATCH] initial commit (from keybase) --- index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..7fa72c9 --- /dev/null +++ b/index.js @@ -0,0 +1,27 @@ +/** + * take a date of assumed timezone and convert to utc + * + * @param {*} d + * @param {*} tz + * @returns + */ +function tzUTC(d, tz) { + // first calculate tz difference + var date = new Date(); + var options = { + year: 'numeric', + month: 'numeric', + day: 'numeric', + hour: 'numeric', + minute: 'numeric', + second: 'numeric', + hour12: false, + timeZone: tz + }; + var tzDate = new Intl.DateTimeFormat('en-US', options).format(date) + var diff = date - new Date(tzDate); + var minutes = Math.floor((diff / 1000) / 60); + var localTime = new Date(d); + localTime.setMinutes(d.getMinutes() + minutes); + return localTime.toUTCString(); +} \ No newline at end of file