What you're trying to do seems valid, however the way you're doing it is prone to failure.
"2020-04-19 23:59:59" is not a format supported by ECMA-262 so parsing is implementation dependent. Apple devices until very recently treated it as an invalid date, so this method will fail for any device running an earlier OS.
A better way is to manually parse the string to remove issues associated with the built–in parser. Similarly for the return value from toLocaleString.
The following manually parses the timestamp, then uses Intl.DateTimeFormat with formatToParts to get the date and time values for any IANA representative location. It uses Date.UTC to generate time values to compare and avoid local DST issues.
Note that if the input timestamp represents a date and time that doesn't exist in the location (i.e. it's in the period when clocks are advanced going into DST) or exists twice (i.e. it's in the period when clocks are wound back going out of DST) then results may or may not be "correct". However, this is an issue for any system comparing such dates and times.
// Return true if current time is before timestamp at loc
function nowIsBeforeDateAtLoc(ts, loc = 'UTC') {
// Get time value for timestamp parsed as UTC
let [Y,M,D,H,m,s] = ts.split(/\D/);
let tsTV = Date.UTC(Y,M-1,D,H,m,s);
// Get current date and time values for loc
let {year, month, day, hour, minute, second} = new Intl.DateTimeFormat('en', {
year:'numeric',
month:'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
hour12: false,
timeZone: loc
}).formatToParts(new Date()).reduce((acc, part) => {
acc[part.type] = part.value;
return acc;
}, Object.create(null));
// Get UTC time value for loc
let locTV = Date.UTC(year, month-1, day, hour, minute, second);
// Debug
// Parsed timestamp
console.log('Cutoff: ' + new Date(tsTV).toISOString().slice(0,-1));
// Current date and time at loc
console.log('Now ' + loc + ' : ' + new Date(locTV).toISOString().slice(0,-1));
return locTV < tsTV;
}
// Example
let cutoffTime = "2020-04-19 23:59:59";
//
console.log('Now is before cutoff at loc? ' + nowIsBeforeDateAtLoc(cutoffTime, 'America/Denver'));
You could also use a library to parse the timestamp for a particular location then compare it to "now", which might be simpler. See this answer to How to initialize a JavaScript Date to a particular time zone.