Daylight Savings Timezone Detection From Strings In JavaScript

Multi tool use


Daylight Savings Timezone Detection From Strings In JavaScript
I've looked in several places but I could not find a solution to this problem. I have some data I'm trying to import and for my case, it contains strings representing dates which are in the Eastern Time Zone (ET). Strings look like this:
July 28, 2018 03:39 PM
If I try to create a new date object in JavaScript, I can create the new date object, but the problem is that there is no ET
timezone, so I can create it either using EST
(Eastern Standard Time) or EDT
(Eastern Daylight Time).
ET
EST
EDT
console.log(new Date('July 28, 2018 03:39 PM EST'));
2018-07-28T19:39:00.000Z
Or
console.log(new Date('July 28, 2018 03:39 PM EDT'));
2018-07-28T20:39:00.000Z
We can clearly see there is one hour difference between both. The rules to determine if Daylight Saving is active or not seems quite complex and can vary from geographic region.
So my question is: is there any solution out there which can detect the applicable time zone (daylight or standard) based on certain parameters? I presume at the minimum, the year, the month, the day, the time and standard time zone would be required?
I could not find any solution to this problem since JavaScript stores all date in UTC. Unless I can find the standard/daylight saving timezone of the string I'm parsing, I cannot reliably create a date object.
I could easily solve it for Eastern Time but, I am sure something better exists out there to solve it for all time zones?
The type of solution I would be looking for would look something like this:
let dateString = 'July 28, 2018 03:39 PM'
let timeZone = getStandardOrDaylightSavingsTZ(dateString, 'EST');
// "timeZone" would be set back to EDT right now because it's daylight savings
console.log(new Date(dateString + ' ' + timeZone));
2018-07-28T20:39:00.000Z
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.