Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ assert.equal(ts, 1457856000000) // one hour later in UTC time...

ts = zt(ts, 'America/Chicago') // 13 Mar, 2016 03:00 CDT
assert.equal(ts, 1457838000000) // ...is 2 hours later in local time,
// because Daylight Savings Time
// because Daylight Savings Time
// went into effect

// Date objects can be used instead of timestamps...
Expand All @@ -37,6 +37,7 @@ let d = new Date(Date.UTC(2016, 2, 13, 7, 2, 3))
// ...and you'll get back a Date object in return...

d = zt(d, 'America/Chicago')
assert(d instanceof Date)

// ...which is convenient for formatted display in local time:

Expand Down Expand Up @@ -74,6 +75,14 @@ ts = zt(ts, 'America/Chicago') // UTC to local
ts = zt(ts, 'America/Chicago', true) // local to UTC
assert.equal(ts, Date.UTC(2016, 2, 13, 8))

// It works for Date objects too:

d = new Date(Date.UTC(2016, 2, 13, 8))
d = zt(d, 'America/Chicago') // UTC to local
d = zt(d, 'America/Chicago', true) // local to UTC
assert(d instanceof Date)
assert.equal(d.getTime(), Date.UTC(2016, 2, 13, 8))

// Offsets can also be retrieved for local to UTC conversions...

ts = Date.UTC(2016, 2, 13, 8)
Expand Down
2 changes: 1 addition & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export function canonicalize (name) {
}

export default function tz (timestamp, name, local, opts) {
if (timestamp instanceof Date) return new Date(tz(timestamp.getTime(), name))
if (timestamp instanceof Date) return new Date(tz(timestamp.getTime(), name, local, opts))
return timestamp + offset(timestamp, name, local, opts) * 6e4
}