date-fns-tz
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -7,3 +7,3 @@ /** | ||
export default function tzIntlTimeZoneName(length, date, options) { | ||
const dtf = getDTF(length, options.timeZone, options.locale) | ||
var dtf = getDTF(length, options.timeZone, options.locale) | ||
return dtf.formatToParts ? partsTimeZone(dtf, date) : hackyTimeZone(dtf, date) | ||
@@ -13,3 +13,3 @@ } | ||
function partsTimeZone(dtf, date) { | ||
const formatted = dtf.formatToParts(date) | ||
var formatted = dtf.formatToParts(date) | ||
return formatted[formatted.length - 1].value | ||
@@ -19,4 +19,4 @@ } | ||
function hackyTimeZone(dtf, date) { | ||
const formatted = dtf.format(date).replace(/\u200E/g, '') | ||
const tzNameMatch = / [\w-+ ]+$/.exec(formatted) | ||
var formatted = dtf.format(date).replace(/\u200E/g, '') | ||
var tzNameMatch = / [\w-+ ]+$/.exec(formatted) | ||
return tzNameMatch ? tzNameMatch[0].substr(1) : '' | ||
@@ -23,0 +23,0 @@ } |
@@ -6,7 +6,7 @@ /** | ||
export default function tzTokenizeDate(date, timeZone) { | ||
const dtf = getDateTimeFormat(timeZone) | ||
var dtf = getDateTimeFormat(timeZone) | ||
return dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date) | ||
} | ||
const typeToPos = { | ||
var typeToPos = { | ||
year: 0, | ||
@@ -21,7 +21,7 @@ month: 1, | ||
function partsOffset(dtf, date) { | ||
const formatted = dtf.formatToParts(date) | ||
const filled = [] | ||
var formatted = dtf.formatToParts(date) | ||
var filled = [] | ||
for (let i = 0; i < formatted.length; i++) { | ||
const { type, value } = formatted[i] | ||
const pos = typeToPos[type] | ||
var { type, value } = formatted[i] | ||
var pos = typeToPos[type] | ||
@@ -36,5 +36,5 @@ if (pos >= 0) { | ||
function hackyOffset(dtf, date) { | ||
const formatted = dtf.format(date).replace(/\u200E/g, '') | ||
const parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted) | ||
const [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed | ||
var formatted = dtf.format(date).replace(/\u200E/g, '') | ||
var parsed = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(formatted) | ||
var [, fMonth, fDay, fYear, fHour, fMinute, fSecond] = parsed | ||
return [fYear, fMonth, fDay, fHour, fMinute, fSecond] | ||
@@ -46,3 +46,3 @@ } | ||
// can be used to extract local time parts as necessary. | ||
const dtfCache = {} | ||
var dtfCache = {} | ||
function getDateTimeFormat(timeZone) { | ||
@@ -49,0 +49,0 @@ if (!dtfCache[timeZone]) { |
import tzIntlTimeZoneName from '../../_lib/tzIntlTimeZoneName' | ||
import tzParseTimezone from '../../_lib/tzParseTimezone' | ||
const MILLISECONDS_IN_MINUTE = 60 * 1000 | ||
var MILLISECONDS_IN_MINUTE = 60 * 1000 | ||
@@ -6,0 +6,0 @@ var formatters = { |
@@ -6,3 +6,3 @@ import dateFnsFormat from 'date-fns/format' | ||
const tzFormattingTokensRegExp = /([xXOz]+)|''|'(''|[^'])+('|$)/g | ||
var tzFormattingTokensRegExp = /([xXOz]+)|''|'(''|[^'])+('|$)/g | ||
@@ -321,7 +321,7 @@ /** | ||
let formatStr = String(dirtyFormatStr) | ||
const options = dirtyOptions || {} | ||
var options = dirtyOptions || {} | ||
const matches = formatStr.match(tzFormattingTokensRegExp) | ||
var matches = formatStr.match(tzFormattingTokensRegExp) | ||
if (matches) { | ||
const date = toDate(dirtyDate, options) | ||
var date = toDate(dirtyDate, options) | ||
formatStr = matches.reduce( | ||
@@ -328,0 +328,0 @@ (result, token) => |
@@ -30,6 +30,6 @@ import tzParseTimezone from '../_lib/tzParseTimezone' | ||
export default function utcToZonedTime(dirtyDate, timeZone, options) { | ||
const date = toDate(dirtyDate, options) | ||
var date = toDate(dirtyDate, options) | ||
// This date has the UTC time values of the input date at the system time zone | ||
const utcDate = new Date( | ||
var utcDate = new Date( | ||
date.getUTCFullYear(), | ||
@@ -43,3 +43,3 @@ date.getUTCMonth(), | ||
// We just need to apply the offset indicated by the time zone to this localized date | ||
const offsetMilliseconds = tzParseTimezone(timeZone, date) | ||
var offsetMilliseconds = tzParseTimezone(timeZone, date) | ||
@@ -46,0 +46,0 @@ return offsetMilliseconds |
@@ -33,5 +33,5 @@ import cloneObject from 'date-fns/_lib/cloneObject' | ||
} | ||
const extendedOptions = cloneObject(options) | ||
var extendedOptions = cloneObject(options) | ||
extendedOptions.timeZone = timeZone | ||
return toDate(date, extendedOptions) | ||
} |
{ | ||
"name": "date-fns-tz", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"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
168989