date-fns-tz
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -18,4 +18,3 @@ "use strict"; | ||
timezoneHH: /^([+-])(\d{2})$/, | ||
timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/, | ||
timezoneIANA: /(UTC|(?:[a-zA-Z]+\/[a-zA-Z_-]+(?:\/[a-zA-Z_]+)?))$/ | ||
timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/ | ||
}; // Parse various time zone offset formats to an offset in milliseconds | ||
@@ -64,5 +63,3 @@ | ||
token = patterns.timezoneIANA.exec(timezoneString); | ||
if (token) { | ||
if (isValidTimezoneIANAString(timezoneString)) { | ||
date = new Date(date || Date.now()); | ||
@@ -123,2 +120,13 @@ var utcDate = isUtcDate ? date : toUtcDate(date); | ||
function isValidTimezoneIANAString(timeZoneString) { | ||
try { | ||
Intl.DateTimeFormat(undefined, { | ||
timeZone: timeZoneString | ||
}); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
} | ||
module.exports = exports.default; |
@@ -10,4 +10,3 @@ import tzTokenizeDate from '../tzTokenizeDate/index.js' | ||
timezoneHH: /^([+-])(\d{2})$/, | ||
timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/, | ||
timezoneIANA: /(UTC|(?:[a-zA-Z]+\/[a-zA-Z_-]+(?:\/[a-zA-Z_]+)?))$/, | ||
timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/ | ||
} | ||
@@ -56,4 +55,3 @@ | ||
// IANA time zone | ||
token = patterns.timezoneIANA.exec(timezoneString) | ||
if (token) { | ||
if (isValidTimezoneIANAString(timezoneString)) { | ||
date = new Date(date || Date.now()) | ||
@@ -131,1 +129,11 @@ var utcDate = isUtcDate ? date : toUtcDate(date) | ||
} | ||
function isValidTimezoneIANAString(timeZoneString) { | ||
try { | ||
Intl.DateTimeFormat(undefined, {timeZone: timeZoneString}); | ||
return true; | ||
} | ||
catch { | ||
return false; | ||
} | ||
} |
{ | ||
"name": "date-fns-tz", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "description": "Time zone support for date-fns v2 with the browser Intl API", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
181484
3115