Skip to content

Commit be02f21

Browse files
committed
feat: Add data and index modules for the year range 1900-2050
1 parent 57368cc commit be02f21

6 files changed

Lines changed: 138 additions & 49 deletions

File tree

rollup.config.js

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import babel from 'rollup-plugin-babel'
2+
import clean from 'rollup-plugin-clean'
23
import { uglify } from 'rollup-plugin-uglify'
34

45
export default [
@@ -9,7 +10,8 @@ export default [
910
format: 'cjs'
1011
},
1112
plugins: [
12-
babel({ exclude: 'node_modules/**' })
13+
babel({ exclude: 'node_modules/**' }),
14+
clean()
1315
]
1416
},
1517
{
@@ -19,7 +21,19 @@ export default [
1921
format: 'cjs'
2022
},
2123
plugins: [
22-
babel({ exclude: 'node_modules/**' })
24+
babel({ exclude: 'node_modules/**' }),
25+
clean()
26+
]
27+
},
28+
{
29+
input: 'src/index-1900-2050.js',
30+
output: {
31+
file: 'dist/index-1900-2050.js',
32+
format: 'cjs'
33+
},
34+
plugins: [
35+
babel({ exclude: 'node_modules/**' }),
36+
clean()
2337
]
2438
},
2539
{
@@ -29,7 +43,8 @@ export default [
2943
format: 'cjs'
3044
},
3145
plugins: [
32-
babel({ exclude: 'node_modules/**' })
46+
babel({ exclude: 'node_modules/**' }),
47+
clean()
3348
]
3449
},
3550
{
@@ -39,7 +54,19 @@ export default [
3954
format: 'cjs'
4055
},
4156
plugins: [
42-
babel({ exclude: 'node_modules/**' })
57+
babel({ exclude: 'node_modules/**' }),
58+
clean()
59+
]
60+
},
61+
{
62+
input: 'src/lookup/data-1900-2050.js',
63+
output: {
64+
file: 'dist/data-1900-2050.js',
65+
format: 'cjs'
66+
},
67+
plugins: [
68+
babel({ exclude: 'node_modules/**' }),
69+
clean()
4370
]
4471
},
4572
{
@@ -49,7 +76,8 @@ export default [
4976
format: 'cjs'
5077
},
5178
plugins: [
52-
babel({ exclude: 'node_modules/**' })
79+
babel({ exclude: 'node_modules/**' }),
80+
clean()
5381
]
5482
},
5583
{
@@ -78,6 +106,19 @@ export default [
78106
uglify()
79107
]
80108
},
109+
{
110+
input: 'src/index-1900-2050.js',
111+
output: {
112+
file: 'dist/index-1900-2050.umd.js',
113+
format: 'umd',
114+
name: 'timezone-support',
115+
sourcemap: true
116+
},
117+
plugins: [
118+
babel({ exclude: 'node_modules/**' }),
119+
uglify()
120+
]
121+
},
81122
{
82123
input: 'src/lookup-convert.js',
83124
output: {
@@ -104,6 +145,19 @@ export default [
104145
uglify()
105146
]
106147
},
148+
{
149+
input: 'src/lookup/data-1900-2050.js',
150+
output: {
151+
file: 'dist/data-1900-2050.umd.js',
152+
format: 'umd',
153+
name: 'timezone-data-1900-2050',
154+
sourcemap: true
155+
},
156+
plugins: [
157+
babel({ exclude: 'node_modules/**' }),
158+
uglify()
159+
]
160+
},
107161
{
108162
input: 'src/parse-format.js',
109163
output: {

src/index-1900-2050.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {
2+
populateTimeZones, listTimeZones, findTimeZone, getUTCOffset, getZonedTime, getUnixTime, setTimeZone, convertTimeToDate, convertDateToTime
3+
} from './lookup-convert'
4+
import data from './lookup/data-1900-2050'
5+
6+
populateTimeZones(data)
7+
8+
export { listTimeZones, findTimeZone, getUTCOffset, getZonedTime, getUnixTime, setTimeZone, convertTimeToDate, convertDateToTime }

src/index-2012-2022.d.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/data-1900-2050.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* global it, expect */
2+
3+
import { populateTimeZones, findTimeZone, getZonedTime } from '../src/lookup-convert'
4+
import limitedData from '../src/lookup/data-1900-2050'
5+
6+
let populated
7+
function ensureTimeZones () {
8+
if (!populated) {
9+
populateTimeZones(limitedData)
10+
populated = true
11+
}
12+
}
13+
14+
it('is exported as an object', () => {
15+
expect(typeof limitedData === 'object').toBeTruthy()
16+
})
17+
18+
it('allows handling dates from years 1900-2050', () => {
19+
ensureTimeZones()
20+
const berlin = findTimeZone('Europe/Berlin')
21+
const isoString = '2018-09-30T09:19:17.276Z'
22+
const date = new Date(isoString)
23+
const berlinTime = getZonedTime(date, berlin)
24+
expect(typeof berlinTime === 'object').toBeTruthy()
25+
const { year, month, day, dayOfWeek, hours, minutes, seconds, milliseconds, epoch, zone } = berlinTime
26+
expect(year).toEqual(2018)
27+
expect(month).toEqual(9)
28+
expect(day).toEqual(30)
29+
expect(dayOfWeek).toEqual(0)
30+
expect(hours).toEqual(11)
31+
expect(minutes).toEqual(19)
32+
expect(seconds).toEqual(17)
33+
expect(milliseconds).toEqual(276)
34+
expect(epoch).toEqual(date.getTime())
35+
expect(typeof zone === 'object').toBeTruthy()
36+
const { abbreviation, offset } = zone
37+
expect(/\w+/.test(abbreviation)).toBeTruthy()
38+
expect(offset).toEqual(-120)
39+
})

test/module-1900-2050.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* global beforeAll, it, expect */
2+
3+
import { findTimeZone, getZonedTime } from '../src/index-1900-2050'
4+
5+
let berlin
6+
7+
beforeAll(() => {
8+
berlin = findTimeZone('Europe/Berlin')
9+
})
10+
11+
it('is exported as a function', () => {
12+
expect(typeof getZonedTime === 'function').toBeTruthy()
13+
})
14+
15+
it('converts the UNIX time to the correct time object', () => {
16+
const unixTime = Date.UTC(2018, 0, 2, 9, 30, 15, 234)
17+
const berlinTime = getZonedTime(unixTime, berlin)
18+
expect(typeof berlinTime === 'object').toBeTruthy()
19+
const { year, month, day, dayOfWeek, hours, minutes, seconds, milliseconds, zone, epoch } = berlinTime
20+
expect(year).toEqual(2018)
21+
expect(month).toEqual(1)
22+
expect(day).toEqual(2)
23+
expect(dayOfWeek).toEqual(2)
24+
expect(hours).toEqual(10)
25+
expect(minutes).toEqual(30)
26+
expect(seconds).toEqual(15)
27+
expect(milliseconds).toEqual(234)
28+
expect(typeof zone === 'object').toBeTruthy()
29+
expect(zone.abbreviation).toEqual('CET')
30+
expect(zone.offset).toEqual(-60)
31+
expect(epoch).toEqual(1514885415234)
32+
})

0 commit comments

Comments
 (0)