This code doesn't solve the problem for directly timestamping time-zones but provides an alternative to supporting preferred time-zones as well creating js acceptable time-stamps converting numerical month to month name dynamically. This is just crude solution open to suggestions.
function getTZId(zone) {
var retId = zone;
if (zone) {
//placeholder to maintain / add new zone id patterns
//a word of caution: some timezones are not supported so offset will be required
var zoneIds = {
'EST':[/ET/,/EST/,/EAST/,/OTT/],
'UTC+5:30':[/IST/,/IND/,/GURG/],
'CST':[/CENTR/,/NA/],
'UTC':[/UTC/,/GMT/,/ZULU/,/Z/,/GREEN/]
}
//default zone id
var defZnId = 'UTC';
var fnd = _.findIndex (
Object.keys( zoneIds ),
//lookup all zone id's for a match among respective zone patterns till first matching zone id is found
znId => {
return (
_.findIndex (
zoneIds[znId],
//match each zone pattern for this zone id till the first match is found
znPtrn=>{
return znPtrn.test( zone.toUpperCase() )
}
) !== -1
)
}
);
//return zone id if matching zone id found else return default zone id: 'UTC'
retId = (fnd!==-1?Object.keys( zoneIds )[fnd]:defZnId);
}
return retId;
}
var yr = "2018", mn = "2", dy = "28", hr = "14", min = "05";
var timezone = "EST";
//get date components for current timezone like month names etc
var tmpDt = (new Date(`${yr}-${mn}-${dy}T${hr}:${min}`)).toDateString().match(/^([A-Za-z]+)\s+([A-Za-z]+)\s+(\d+)\s+(\d+)$/i);
//use above code to create appropriate time stamp
return (new Date(`${tmpDt[2]} ${tmpDt[3]}, ${yr} ${hr}:${min}:00 ${getTZId(tmZoneStr)}`));