Skip to content

Commit 81be18b

Browse files
authored
remove luxon (#585)
* remove luxon * fix dates * set timezone to UTC
1 parent 70fd717 commit 81be18b

File tree

5 files changed

+39
-37
lines changed

5 files changed

+39
-37
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"cli-select": "^1.1.2",
4040
"compile-json-stringify": "^0.1.2",
4141
"is-my-json-valid": "^2.20.0",
42-
"luxon": "^3.0.1",
4342
"simple-git": "^3.7.1",
4443
"standard": "^17.0.0",
4544
"tap": "^16.0.1",

test/allof.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict'
22

33
const test = require('tap').test
4-
const { DateTime } = require('luxon')
54
const build = require('..')
65

6+
process.env.TZ = 'UTC'
7+
78
test('allOf: combine type and format ', (t) => {
89
t.plan(1)
910

@@ -14,9 +15,9 @@ test('allOf: combine type and format ', (t) => {
1415
]
1516
}
1617
const stringify = build(schema)
17-
const date = new Date()
18+
const date = new Date(1674263005800)
1819
const value = stringify(date)
19-
t.equal(value, `"${DateTime.fromJSDate(date).toFormat('HH:mm:ss')}"`)
20+
t.equal(value, '"01:03:25"')
2021
})
2122

2223
test('allOf: combine additional properties ', (t) => {

test/anyof.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict'
22

3-
const { DateTime } = require('luxon')
43
const { test } = require('tap')
54
const build = require('..')
65

6+
process.env.TZ = 'UTC'
7+
78
test('object with multiple types field', (t) => {
89
t.plan(2)
910

@@ -519,10 +520,10 @@ test('anyOf object with nested field date of type string with format or null', (
519520
const withOneOfStringify = build(withOneOfSchema)
520521

521522
const data = {
522-
prop: { nestedProp: new Date() }
523+
prop: { nestedProp: new Date(1674263005800) }
523524
}
524525

525-
t.equal(withOneOfStringify(data), `{"prop":{"nestedProp":"${DateTime.fromJSDate(data.prop.nestedProp).toISODate()}"}}`)
526+
t.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"2023-01-21"}}')
526527
})
527528

528529
test('anyOf object with nested field time of type string with format or null', (t) => {
@@ -547,10 +548,9 @@ test('anyOf object with nested field time of type string with format or null', (
547548
const withOneOfStringify = build(withOneOfSchema)
548549

549550
const data = {
550-
prop: { nestedProp: new Date() }
551+
prop: { nestedProp: new Date(1674263005800) }
551552
}
552-
553-
t.equal(withOneOfStringify(data), `{"prop":{"nestedProp":"${DateTime.fromJSDate(data.prop.nestedProp).toFormat('HH:mm:ss')}"}}`)
553+
t.equal(withOneOfStringify(data), '{"prop":{"nestedProp":"01:03:25"}}')
554554
})
555555

556556
test('anyOf object with field date of type string with format or null', (t) => {

test/date.test.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
'use strict'
22

33
const test = require('tap').test
4-
const { DateTime } = require('luxon')
54
const validator = require('is-my-json-valid')
65
const build = require('..')
76

7+
process.env.TZ = 'UTC'
8+
89
test('render a date in a string as JSON', (t) => {
910
t.plan(2)
1011

1112
const schema = {
1213
title: 'a date in a string',
1314
type: 'string'
1415
}
15-
const toStringify = new Date()
16+
const toStringify = new Date(1674263005800)
1617

1718
const validate = validator(schema)
1819
const stringify = build(schema)
@@ -30,7 +31,7 @@ test('render a date in a string when format is date-format as ISOString', (t) =>
3031
type: 'string',
3132
format: 'date-time'
3233
}
33-
const toStringify = new Date()
34+
const toStringify = new Date(1674263005800)
3435

3536
const validate = validator(schema)
3637
const stringify = build(schema)
@@ -49,7 +50,7 @@ test('render a nullable date in a string when format is date-format as ISOString
4950
format: 'date-time',
5051
nullable: true
5152
}
52-
const toStringify = new Date()
53+
const toStringify = new Date(1674263005800)
5354

5455
const validate = validator(schema)
5556
const stringify = build(schema)
@@ -67,13 +68,13 @@ test('render a date in a string when format is date as YYYY-MM-DD', (t) => {
6768
type: 'string',
6869
format: 'date'
6970
}
70-
const toStringify = new Date()
71+
const toStringify = new Date(1674263005800)
7172

7273
const validate = validator(schema)
7374
const stringify = build(schema)
7475
const output = stringify(toStringify)
7576

76-
t.equal(output, `"${DateTime.fromJSDate(toStringify).toISODate()}"`)
77+
t.equal(output, '"2023-01-21"')
7778
t.ok(validate(JSON.parse(output)), 'valid schema')
7879
})
7980

@@ -86,13 +87,13 @@ test('render a nullable date in a string when format is date as YYYY-MM-DD', (t)
8687
format: 'date',
8788
nullable: true
8889
}
89-
const toStringify = new Date()
90+
const toStringify = new Date(1674263005800)
9091

9192
const validate = validator(schema)
9293
const stringify = build(schema)
9394
const output = stringify(toStringify)
9495

95-
t.equal(output, `"${DateTime.fromJSDate(toStringify).toISODate()}"`)
96+
t.equal(output, '"2023-01-21"')
9697
t.ok(validate(JSON.parse(output)), 'valid schema')
9798
})
9899

@@ -110,7 +111,7 @@ test('verify padding for rendered date in a string when format is date', (t) =>
110111
const stringify = build(schema)
111112
const output = stringify(toStringify)
112113

113-
t.equal(output, `"${DateTime.fromJSDate(toStringify).toISODate()}"`)
114+
t.equal(output, '"2020-01-01"')
114115
t.ok(validate(JSON.parse(output)), 'valid schema')
115116
})
116117

@@ -122,7 +123,7 @@ test('render a date in a string when format is time as kk:mm:ss', (t) => {
122123
type: 'string',
123124
format: 'time'
124125
}
125-
const toStringify = new Date()
126+
const toStringify = new Date(1674263005800)
126127

127128
const validate = validator(schema)
128129
const stringify = build(schema)
@@ -131,7 +132,7 @@ test('render a date in a string when format is time as kk:mm:ss', (t) => {
131132
validate(JSON.parse(output))
132133
t.equal(validate.errors, null)
133134

134-
t.equal(output, `"${DateTime.fromJSDate(toStringify).toFormat('HH:mm:ss')}"`)
135+
t.equal(output, '"01:03:25"')
135136
t.ok(validate(JSON.parse(output)), 'valid schema')
136137
})
137138

@@ -144,7 +145,7 @@ test('render a nullable date in a string when format is time as kk:mm:ss', (t) =
144145
format: 'time',
145146
nullable: true
146147
}
147-
const toStringify = new Date()
148+
const toStringify = new Date(1674263005800)
148149

149150
const validate = validator(schema)
150151
const stringify = build(schema)
@@ -153,7 +154,7 @@ test('render a nullable date in a string when format is time as kk:mm:ss', (t) =
153154
validate(JSON.parse(output))
154155
t.equal(validate.errors, null)
155156

156-
t.equal(output, `"${DateTime.fromJSDate(toStringify).toFormat('HH:mm:ss')}"`)
157+
t.equal(output, '"01:03:25"')
157158
t.ok(validate(JSON.parse(output)), 'valid schema')
158159
})
159160

@@ -165,7 +166,7 @@ test('render a midnight time', (t) => {
165166
type: 'string',
166167
format: 'time'
167168
}
168-
const midnight = new Date(new Date().setHours(24))
169+
const midnight = new Date(new Date(1674263005800).setHours(24))
169170

170171
const validate = validator(schema)
171172
const stringify = build(schema)
@@ -174,7 +175,7 @@ test('render a midnight time', (t) => {
174175
validate(JSON.parse(output))
175176
t.equal(validate.errors, null)
176177

177-
t.equal(output, `"${DateTime.fromJSDate(midnight).toFormat('HH:mm:ss')}"`)
178+
t.equal(output, '"00:03:25"')
178179
t.ok(validate(JSON.parse(output)), 'valid schema')
179180
})
180181

@@ -195,7 +196,7 @@ test('verify padding for rendered date in a string when format is time', (t) =>
195196
validate(JSON.parse(output))
196197
t.equal(validate.errors, null)
197198

198-
t.equal(output, `"${DateTime.fromJSDate(toStringify).toFormat('HH:mm:ss')}"`)
199+
t.equal(output, '"01:01:01"')
199200
t.ok(validate(JSON.parse(output)), 'valid schema')
200201
})
201202

@@ -212,7 +213,7 @@ test('render a nested object in a string when type is date-format as ISOString',
212213
}
213214
}
214215
}
215-
const toStringify = { date: new Date() }
216+
const toStringify = { date: new Date(1674263005800) }
216217

217218
const validate = validator(schema)
218219
const stringify = build(schema)
@@ -384,11 +385,11 @@ test('serializing null value', t => {
384385
]
385386
}
386387

387-
const date = new Date()
388+
const date = new Date(1674263005800)
388389
const input = { updatedAt: date }
389390
const { output } = serialize(schema, input)
390391

391-
t.equal(output, JSON.stringify({ updatedAt: DateTime.fromJSDate(date).toFormat('HH:mm:ss') }))
392+
t.equal(output, JSON.stringify({ updatedAt: '01:03:25' }))
392393
})
393394

394395
t.test('format::time, Date object', t => {
@@ -403,10 +404,10 @@ test('serializing null value', t => {
403404
]
404405
}
405406

406-
const date = new Date()
407+
const date = new Date(1674263005800)
407408
const { output } = serialize(schema, date)
408409

409-
t.equal(output, `"${DateTime.fromJSDate(date).toFormat('HH:mm:ss')}"`)
410+
t.equal(output, '"01:03:25"')
410411
})
411412

412413
t.test('format::time, Date object', t => {
@@ -497,7 +498,7 @@ test('Validate Date object as string type', (t) => {
497498
{ type: 'string' }
498499
]
499500
}
500-
const toStringify = new Date()
501+
const toStringify = new Date(1674263005800)
501502

502503
const stringify = build(schema)
503504
const output = stringify(toStringify)
@@ -520,10 +521,10 @@ test('nullable date', (t) => {
520521

521522
const stringify = build(schema)
522523

523-
const data = new Date()
524+
const data = new Date(1674263005800)
524525
const result = stringify(data)
525526

526-
t.same(result, `"${DateTime.fromJSDate(data).toISODate()}"`)
527+
t.same(result, '"2023-01-21"')
527528
})
528529

529530
test('non-date format should not affect data serialization (issue #491)', (t) => {

test/if-then-else.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
'use strict'
22

33
const t = require('tap')
4-
const { DateTime } = require('luxon')
54
const build = require('..')
65

6+
process.env.TZ = 'UTC'
7+
78
const schema = {
89
type: 'object',
910
properties: {
@@ -381,9 +382,9 @@ t.test('if/else with string format', (t) => {
381382

382383
const stringify = build(schema)
383384

384-
const date = new Date()
385+
const date = new Date(1674263005800)
385386

386-
t.equal(stringify(date), `"${DateTime.fromJSDate(date).toISODate()}"`)
387+
t.equal(stringify(date), '"2023-01-21"')
387388
t.equal(stringify('Invalid'), '"Invalid"')
388389
})
389390

0 commit comments

Comments
 (0)