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.3.1 to 0.3.2

date/format.js

12

add.js

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

var parseIsoDate = require("./iso-date/parse.js")
var formatIsoDate = require("./iso-date/format.js")
var formatDate = require("./date/format.js")
var parseToMoment = require("./moment/parse.js")

@@ -93,5 +93,7 @@ var formatFromMoment = require("./moment/format.js")

datetime.setUTCFullYear(datetime.getUTCFullYear() + amount)
} else {
throw new Error("browser-tz/add: invalid type ", type)
}
var formatted = formatIsoDate(datetime, isoDate.offset)
var formatted = formatDate(datetime, isoDate.offset)
return formatted

@@ -115,3 +117,2 @@ }

if (!time) {
// console.log("BAD DATE", String(time))
return "BAD DATE"

@@ -129,3 +130,2 @@ }

if (localISO === "BAD DATE") {
// console.log("BAD DATE", date)
return localISO

@@ -135,2 +135,3 @@ }

var isoDate = parseIsoDate(localISO)
// console.log("isoDate", localISO)

@@ -144,5 +145,2 @@ if (isoDate.offset) {

var targetDate = addNoTimezone(type, { iso: localISO }, amount)
if (targetDate.indexOf("NaN") !== -1) {
// console.log("targetDate", targetDate, isoDate, localISO, date)
}

@@ -149,0 +147,0 @@ return IsoString({ iso: targetDate, timezone: date.timezone })

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

format: format,
add: add,
addMillisecond: add.bind(null, "millisecond"),

@@ -18,0 +19,0 @@ addSecond: add.bind(null, "second"),

module.exports = formatIsoDate
function formatIsoDate(isoDate, offset) {
if (isDate(isoDate)) {
return isoDate.getUTCFullYear() + "-" +
doubleDigit(isoDate.getUTCMonth() + 1) + "-" +
doubleDigit(isoDate.getUTCDate()) + "T" +
doubleDigit(isoDate.getUTCHours()) + ":" +
doubleDigit(isoDate.getUTCMinutes()) + ":" +
doubleDigit(isoDate.getUTCSeconds()) + "." +
tripleDigit(isoDate.getUTCMilliseconds()) +
(offset || "")
}
return isoDate.year + "-" +

@@ -25,6 +14,2 @@ doubleDigit(isoDate.month) + "-" +

function isDate(d) {
return Object.prototype.toString.call(d) === "[object Date]"
}
function doubleDigit(str) {

@@ -31,0 +16,0 @@ str = String(str)

{
"name": "browser-tz",
"version": "0.3.1",
"version": "0.3.2",
"description": "Timezone specific manipulation of datetime strings",

@@ -38,3 +38,3 @@ "keywords": [],

"travis-test": "istanbul cover ./test/index.js && ((cat coverage/lcov.info | coveralls) || exit 0)",
"cover": "istanbul cover --report none --print detail ./test/index.js",
"cover": "istanbul cover --report none --print detail ./test/index.js && istanbul report html",
"view-cover": "istanbul report html && google-chrome ./coverage/index.html",

@@ -41,0 +41,0 @@ "test-browser": "testem-browser ./test/browser/index.js",

# browser-tz
<!--
[![build status][1]][2]
[![NPM version][3]][4]
[![Coverage Status][5]][6]
[![gemnasium Dependency Status][7]][8]
[![Davis Dependency status][9]][10]
-->
[![build status][1]][2] [![Coverage Status][5]][6] [![gemnasium Dependency Status][7]][8] [![Davis Dependency status][9]][10]
[![NPM][3]][4]
[![browser support][11]][12]

@@ -125,4 +121,4 @@

[2]: https://travis-ci.org/Colingo/browser-tz
[3]: https://badge.fury.io/js/browser-tz.png
[4]: https://badge.fury.io/js/browser-tz
[3]: https://nodei.co/npm/browser-tz.png
[4]: https://nodei.co/npm/browser-tz/
[5]: https://coveralls.io/repos/Colingo/browser-tz/badge.png

@@ -137,1 +133,2 @@ [6]: https://coveralls.io/r/Colingo/browser-tz

[13]: https://github.com/Colingo/browser-tz/blob/master/docs.mli

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

"2013-02-28T00:00:00.000Z")
assert.equal(tz.addMonth("2012-01-30T00:00:00Z", 1),
"2012-02-29T00:00:00.000Z")
assert.equal(tz.addMonth({

@@ -324,2 +326,34 @@ iso: "2013-01-30T00:00:00Z",

test("add with local format", function (assert) {
assert.equal(tz.addWeek({
iso: "2013-03-03T02:00:00.000",
timezone: "America/Toronto"
}, 1), "2013-03-10T03:00:00.000-04:00")
assert.end()
})
test("add with timezone syntax", function (assert) {
var d = tz.add("month", "2013-01-30T00:00:00Z", "America/Toronto", 1)
assert.equal(d, "2013-02-28T19:00:00.000-05:00")
assert.end()
})
test("no amount throws", function (assert) {
assert.throws(function () {
tz.add("month", "2013-01-30T00:00:00Z")
}, /must add an amount/)
assert.end()
})
test("add invalid type", function (assert) {
assert.throws(function () {
tz.add("foobar", "2013-11-03T00:00:00", 1)
}, /invalid type/)
assert.end()
})
function assertBadDates(assert, operation) {

@@ -326,0 +360,0 @@ assert.equal(tz[operation]("JUNK", 1), "BAD DATE")

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

assert.equal(tz.format("2013-08-10T18:00:00", "hh:mm"), "06:00")
assert.equal(tz.format("2013-08-10T18:00:00"), "2013-08-10T18:00:00-07:00")
assert.end()
})

Sorry, the diff of this file is not supported yet

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