Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

browser-tz

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-tz - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

test/iso-string.js

5

add.js

@@ -44,3 +44,6 @@ // var SECOND = 1000

var datetime = new Date(date.iso)
// firefox parses dates without an offset of them as UTC
// Chrome & opera & IE parses iso dates without an offset on
// them as local time
var datetime = new Date(isoDate.offset ? date.iso : date.iso + "Z")

@@ -47,0 +50,0 @@ if (type === "week") {

6

iso-date/parse.js
var isISOString = new RegExp(
"(\\d\\d\\d\\d)-" + // year
"(\\d\\d)-" + // month
"(\\d\\d\\d\\d)\\-" + // year
"(\\d\\d)\\-" + // month
"(\\d\\d)T" + // day

@@ -9,3 +9,3 @@ "(\\d\\d):" + // hour

"\\.?(\\d\\d\\d)?" + // optional milliseconds
"([Z(-\\d\\d:\\d\\d)])?" // optional timezone information
"([Z(\\-\\d\\d:\\d\\d)])?" // optional timezone information
)

@@ -12,0 +12,0 @@

@@ -28,4 +28,5 @@ var moment = require("moment-timezone/moment-timezone.js")

return formatFromMoment(parseToMoment(date, isoDate))
var time = parseToMoment(date, isoDate)
return formatFromMoment(time)
}

@@ -20,2 +20,3 @@ var moment = require("moment-timezone/moment-timezone.js")

var time = moment(date.iso).tz(date.timezone)
// console.log("parseToMoment.time", String(time))

@@ -26,8 +27,34 @@ // moment casts "local" dates to be in the machine timezone

if (!isoDate.offset) {
setCorrectLocalTime(time, isoDate)
}
return time
}
function setCorrectLocalTime(time, isoDate) {
time.date(isoDate.day)
// console.log("parseToMoment.first-day", String(time))
// go back an extra hour to jump over the Timezone gap
// this make ambigious local times always favor the
// earliest time. so when 1am happens twice because 2am
// switches back to 1am it picks the first 1am
time.hour(Math.max(isoDate.hour - 1, 0))
// console.log("parseToMoment.first-hour", String(time))
if (time.date() !== isoDate.day) {
// since we are jumping an extra hour back to favor the
// earlier time its possible to set the hour to 0
// but actually have it be -1 because of a timezone jump
// which means we went to yesterday and have to set the
// day back again. We have to set the hour to midday
// otherwise jumping to a day might jump us over the day
// if we apply the timezone
time.hour(12)
time.date(isoDate.day)
// go back an extra hour to jump over the Timezone gap
// this make ambigious local times always favor the
// earliest time. so when 1am happens twice because 2am
// switches back to 1am it picks the first 1am
time.hour(Math.max(isoDate.hour - 1, 0))
// console.log("parseToMoment.second-day", String(time))
}
var secondHour, thirdHour
if (time.hour() !== isoDate.hour) {
// changing hour across a TZ gap is buggy. So we

@@ -37,6 +64,34 @@ // set the hour twice, once to cross the timezone gap

time.hour(isoDate.hour)
time.minute(isoDate.minute)
secondHour = time.hour()
// console.log("parseToMoment.second-hour", String(time))
}
return time
if (time.hour() !== isoDate.hour) {
// We may not have actually passed over the TZ if we
// are really close to it because going back that extra
// hour the first time to fix the other bug might not
// get us over the timezone. So we are definitely on
// the correct side of the timezone on the second hour()
// set so we need a third set to get the time correct
time.hour(isoDate.hour)
thirdHour = time.hour()
// console.log("parseToMoment.third-hour", String(time))
}
if (time.hour() !== isoDate.hour) {
// If we were unable to get the hour to be the exact
// hour we want then we must be setting it to a time that
// doesn't exist like 2am on a DST where time jumps from
// 1.59am to 3.01am
// The correct behaviour we want is to set the hour
// to the later one which is the secondHour variable
time.hour(secondHour)
// we have to set the hour twice to get it to converge
// properly to the correct hour since we jumped across
// a timezone change again
time.hour(secondHour)
// console.log("parseToMoment.fourth-hour", String(time))
}
time.minute(isoDate.minute)
}
{
"name": "browser-tz",
"version": "0.1.2",
"version": "0.1.3",
"description": "Timezone specific manipulation of datetime strings",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -11,3 +11,3 @@ # browser-tz

<!-- [![browser support][11]][12] -->
[![browser support][11]][12]

@@ -14,0 +14,0 @@ Timezone specific manipulation of datetime strings

@@ -30,4 +30,4 @@ var test = require("tape")

require("./time.js")
require("./iso-string.js")
require("./add.js")
require("./format.js")
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc