initial commit (from keybase)

This commit is contained in:
AJ ONeal 2019-06-12 08:39:58 +00:00
parent bb23ae70d1
commit be8d138cd0
1 changed files with 27 additions and 0 deletions

27
index.js Normal file
View File

@ -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();
}