Skip to content

Commit

Permalink
fix: Do not add epoch property with the pre-computed UNIX time in set…
Browse files Browse the repository at this point in the history
…TimeZone

It is not available there and would not mean performance improvement thus.
  • Loading branch information
prantlf committed Sep 3, 2018
1 parent bea4262 commit a4613c1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/convert/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ function getTransition (unixTime, timeZone) {
return { abbreviation, offset }
}

function attachEpoch (time, unixTime) {
Object.defineProperty(time, 'epoch', { value: unixTime })
}

function setTimeZone (time, timeZone, options) {
if (time instanceof Date) {
const { useUTC } = options || {}
Expand All @@ -39,7 +35,6 @@ function setTimeZone (time, timeZone, options) {
const unixTime = getUnixTimeFromUTC(time)
const { abbreviation, offset } = getTransition(unixTime, timeZone)
time.zone = { abbreviation, offset }
attachEpoch(time, unixTime)
return time
}

Expand All @@ -52,7 +47,7 @@ function getZonedTime (date, timeZone) {
}
const time = getUTCTime(date)
time.zone = { abbreviation, offset }
attachEpoch(time, unixTime)
Object.defineProperty(time, 'epoch', { value: unixTime })
return time
}

Expand Down
4 changes: 1 addition & 3 deletions test/setTimeZone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { findTimeZone, setTimeZone } = require('../dist/index')
let berlin

function checkTime (time, checkSeconds) {
const { year, month, day, hours, minutes, seconds, milliseconds, zone, epoch } = time
const { year, month, day, hours, minutes, seconds, milliseconds, zone } = time
expect(year).toEqual(2018)
expect(month).toEqual(1)
expect(day).toEqual(2)
Expand All @@ -14,11 +14,9 @@ function checkTime (time, checkSeconds) {
if (checkSeconds) {
expect(seconds).toEqual(40)
expect(milliseconds).toEqual(50)
expect(epoch).toEqual(1514889040050)
} else {
expect(seconds).toEqual(0)
expect(milliseconds).toEqual(0)
expect(epoch).toEqual(1514889000000)
}
expect(typeof zone === 'object').toBeTruthy()
expect(zone.abbreviation).toEqual('CET')
Expand Down

0 comments on commit a4613c1

Please sign in to comment.