-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows more lightweight time zone computations, if the time object is implemented in a high-level library. Returns only the time zone abbreviation and the difference to UTC to be added to the time value to get the unix time.
- Loading branch information
Showing
7 changed files
with
85 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { | ||
populateTimeZones, listTimeZones, findTimeZone, setTimeZone, getZonedTime, getUnixTime | ||
populateTimeZones, listTimeZones, findTimeZone, getUTCOffset, getZonedTime, getUnixTime, setTimeZone | ||
} from './lookup-convert' | ||
import data from './lookup/data' | ||
|
||
populateTimeZones(data) | ||
|
||
export { listTimeZones, findTimeZone, setTimeZone, getZonedTime, getUnixTime } | ||
export { listTimeZones, findTimeZone, getUTCOffset, getZonedTime, getUnixTime, setTimeZone } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { populateTimeZones, listTimeZones, findTimeZone } from './lookup/lookup' | ||
import { setTimeZone, getZonedTime, getUnixTime } from './convert/convert' | ||
import { getUTCOffset, getZonedTime, getUnixTime, setTimeZone } from './convert/convert' | ||
|
||
export { | ||
populateTimeZones, listTimeZones, findTimeZone, setTimeZone, getZonedTime, getUnixTime | ||
populateTimeZones, listTimeZones, findTimeZone, getUTCOffset, getZonedTime, getUnixTime, setTimeZone | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* global beforeAll, it, expect */ | ||
|
||
const { findTimeZone, getUTCOffset } = require('../dist/index') | ||
|
||
let berlin | ||
|
||
beforeAll(() => { | ||
berlin = findTimeZone('Europe/Berlin') | ||
}) | ||
|
||
it('is exported as a function', () => { | ||
expect(typeof getUTCOffset === 'function').toBeTruthy() | ||
}) | ||
|
||
it('computes the time zone from the UNIX time', () => { | ||
const unixTime = Date.UTC(2018, 0, 2, 9, 30, 15, 234) | ||
const zone = getUTCOffset(unixTime, berlin) | ||
expect(typeof zone === 'object').toBeTruthy() | ||
expect(zone.abbreviation).toEqual('CET') | ||
expect(zone.offset).toEqual(-60) | ||
}) | ||
|
||
it('accepts a Date object instead of a numeric UNIX time', () => { | ||
const utcDate = new Date(Date.UTC(2018, 6, 2, 9, 30, 15, 234)) | ||
const zone = getUTCOffset(utcDate, berlin) | ||
expect(typeof zone === 'object').toBeTruthy() | ||
expect(zone.abbreviation).toEqual('CEST') | ||
expect(zone.offset).toEqual(-120) | ||
}) |