date-fns-tz
Advanced tools
Comparing version 1.1.6 to 1.1.7
@@ -118,3 +118,7 @@ "use strict"; | ||
var validIANATimezoneCache = {}; | ||
function isValidTimezoneIANAString(timeZoneString) { | ||
if (validIANATimezoneCache[timeZoneString]) return true; | ||
try { | ||
@@ -124,2 +128,3 @@ Intl.DateTimeFormat(undefined, { | ||
}); | ||
validIANATimezoneCache[timeZoneString] = true; | ||
return true; | ||
@@ -126,0 +131,0 @@ } catch (error) { |
@@ -10,3 +10,3 @@ import tzTokenizeDate from '../tzTokenizeDate/index.js' | ||
timezoneHH: /^([+-])(\d{2})$/, | ||
timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/ | ||
timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/, | ||
} | ||
@@ -129,9 +129,12 @@ | ||
var validIANATimezoneCache = {} | ||
function isValidTimezoneIANAString(timeZoneString) { | ||
if (validIANATimezoneCache[timeZoneString]) return true | ||
try { | ||
Intl.DateTimeFormat(undefined, {timeZone: timeZoneString}); | ||
return true; | ||
Intl.DateTimeFormat(undefined, { timeZone: timeZoneString }) | ||
validIANATimezoneCache[timeZoneString] = true | ||
return true | ||
} catch (error) { | ||
return false; | ||
return false | ||
} | ||
} |
@@ -324,6 +324,19 @@ import dateFnsFormat from 'date-fns/esm/format' | ||
var date = toDate(dirtyDate, options) | ||
// Work through each match and replace the tz token in the format string with the quoted | ||
// formatted time zone so the remaining tokens can be filled in by date-fns#format. | ||
formatStr = matches.reduce(function (result, token) { | ||
return token[0] === "'" | ||
? result | ||
: result.replace(token, "'" + formatters[token[0]](date, token, null, options) + "'") | ||
if (token[0] === "'") { | ||
return result // This is a quoted portion, matched only to ensure we don't match inside it | ||
} | ||
var pos = result.indexOf(token) | ||
var precededByQuotedSection = result[pos - 1] === "'" | ||
var replaced = result.replace( | ||
token, | ||
"'" + formatters[token[0]](date, token, null, options) + "'" | ||
) | ||
// If the replacement results in two adjoining quoted strings, the back to back quotes | ||
// are removed so it doesn't look like an escaped quote. | ||
return precededByQuotedSection | ||
? replaced.substring(0, pos - 1) + replaced.substring(pos + 1) | ||
: replaced | ||
}, formatStr) | ||
@@ -330,0 +343,0 @@ } |
@@ -334,5 +334,16 @@ "use strict"; | ||
if (matches) { | ||
var date = (0, _toDate.default)(dirtyDate, options); | ||
var date = (0, _toDate.default)(dirtyDate, options); // Work through each match and replace the tz token in the format string with the quoted | ||
// formatted time zone so the remaining tokens can be filled in by date-fns#format. | ||
formatStr = matches.reduce(function (result, token) { | ||
return token[0] === "'" ? result : result.replace(token, "'" + _formatters.default[token[0]](date, token, null, options) + "'"); | ||
if (token[0] === "'") { | ||
return result; // This is a quoted portion, matched only to ensure we don't match inside it | ||
} | ||
var pos = result.indexOf(token); | ||
var precededByQuotedSection = result[pos - 1] === "'"; | ||
var replaced = result.replace(token, "'" + _formatters.default[token[0]](date, token, null, options) + "'"); // If the replacement results in two adjoining quoted strings, the back to back quotes | ||
// are removed so it doesn't look like an escaped quote. | ||
return precededByQuotedSection ? replaced.substring(0, pos - 1) + replaced.substring(pos + 1) : replaced; | ||
}, formatStr); | ||
@@ -339,0 +350,0 @@ } |
{ | ||
"name": "date-fns-tz", | ||
"version": "1.1.6", | ||
"version": "1.1.7", | ||
"sideEffects": false, | ||
"description": "Time zone support for date-fns v2 with the browser Intl API", | ||
"description": "Time zone support for date-fns v2 with the Intl API", | ||
"author": "Marnus Weststrate <marnusw@gmail.com>", | ||
"license": "MIT", | ||
"keywords": [ | ||
"date-fns", | ||
"timezone", | ||
"time zone", | ||
"date", | ||
"time", | ||
"parse", | ||
"format", | ||
"immutable" | ||
], | ||
"repository": "https://github.com/marnusw/date-fns-tz", | ||
@@ -42,19 +52,19 @@ "engine": { | ||
"devDependencies": { | ||
"@babel/cli": "^7.5.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/node": "^7.5.5", | ||
"@babel/plugin-transform-arrow-functions": "^7.2.0", | ||
"@babel/plugin-transform-block-scoping": "^7.5.5", | ||
"@babel/plugin-transform-destructuring": "^7.5.0", | ||
"@babel/cli": "^7.15.4", | ||
"@babel/core": "^7.15.5", | ||
"@babel/node": "^7.15.4", | ||
"@babel/plugin-transform-arrow-functions": "^7.14.5", | ||
"@babel/plugin-transform-block-scoping": "^7.15.3", | ||
"@babel/plugin-transform-destructuring": "^7.14.7", | ||
"@babel/plugin-transform-modules-commonjs": "^7.5.0", | ||
"@babel/plugin-transform-parameters": "^7.4.4", | ||
"@babel/plugin-transform-template-literals": "^7.4.4", | ||
"@typescript-eslint/eslint-plugin": "^4.4.0", | ||
"@typescript-eslint/parser": "^4.4.0", | ||
"babel-eslint": "^10.0.2", | ||
"babel-loader": "^8.0.6", | ||
"babel-plugin-add-module-exports": "^1.0.2", | ||
"@typescript-eslint/eslint-plugin": "^4.31.0", | ||
"@typescript-eslint/parser": "^4.31.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-loader": "^8.2.2", | ||
"babel-plugin-add-module-exports": "^1.0.4", | ||
"babel-preset-power-assert": "^3.0.0", | ||
"cross-env": "^7.0.3", | ||
"date-fns": "^2.16.1", | ||
"date-fns": "^2.23.0", | ||
"eslint": "^7.11.0", | ||
@@ -65,4 +75,4 @@ "eslint-config-prettier": "^7.2.0", | ||
"husky": "^4.3.0", | ||
"jsdoc-to-markdown": "leshakoss/jsdoc-to-markdown", | ||
"json-loader": "^0.5.3", | ||
"jsdoc-to-markdown": "^7.0.1", | ||
"json-loader": "^0.5.7", | ||
"karma": "^3.1.4", | ||
@@ -69,0 +79,0 @@ "karma-benchmark": "^1.0.4", |
183246
3141