1 |
|
2 | 'use strict'
|
3 |
|
4 | const expect = require('chai').expect
|
5 |
|
6 | const utils = require('../src/utils')
|
7 |
|
8 | const dates = [[
|
9 | new Date(Date.UTC(2016, 0, 1, 8, 22, 33, 392)),
|
10 | '2016-01-01T08:22:33.392000000Z'
|
11 | ], [
|
12 | new Date(Date.UTC(2016, 11, 30, 20, 2, 3, 392)),
|
13 | '2016-12-30T20:02:03.392000000Z'
|
14 | ], [
|
15 | new Date(Date.UTC(2016, 11, 30, 20, 2, 5, 297)),
|
16 | '2016-12-30T20:02:05.297000000Z'
|
17 | ], [
|
18 | new Date(Date.UTC(2012, 1, 25, 10, 10, 10, 10)),
|
19 | '2012-02-25T10:10:10.10000000Z'
|
20 | ]]
|
21 |
|
22 | describe('utils', () => {
|
23 | it('toRFC3339', () => {
|
24 | dates.forEach((c) => {
|
25 | expect(utils.toRFC3339(c[0])).to.be.eql(c[1])
|
26 | })
|
27 | })
|
28 |
|
29 | it('parseRFC3339', () => {
|
30 | dates.forEach((c) => {
|
31 | expect(utils.parseRFC3339(c[1])).to.be.eql(c[0])
|
32 | })
|
33 | })
|
34 |
|
35 | it('to and from RFC3339', () => {
|
36 | dates.forEach((c) => {
|
37 | expect(
|
38 | utils.parseRFC3339(utils.toRFC3339(c[0]))
|
39 | ).to.be.eql(
|
40 | c[0]
|
41 | )
|
42 | expect(
|
43 | utils.toRFC3339(utils.parseRFC3339(c[1]))
|
44 | ).to.be.eql(
|
45 | c[1]
|
46 | )
|
47 | })
|
48 | })
|
49 | })
|