Skip to content

Commit 549f1f4

Browse files
fix: set 23 hour cycle (#427)
1 parent 40a7ec4 commit 549f1f4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Serializer {
148148
asTime (date, skipQuotes) {
149149
const quotes = skipQuotes === true ? '' : '"'
150150
if (date instanceof Date) {
151-
const hour = new Intl.DateTimeFormat('en', { hour: 'numeric', hour12: false }).format(date)
151+
const hour = new Intl.DateTimeFormat('en', { hour: 'numeric', hourCycle: 'h23' }).format(date)
152152
const minute = new Intl.DateTimeFormat('en', { minute: 'numeric' }).format(date)
153153
const second = new Intl.DateTimeFormat('en', { second: 'numeric' }).format(date)
154154
return quotes + this.pad2Zeros(hour) + ':' + this.pad2Zeros(minute) + ':' + this.pad2Zeros(second) + quotes

test/date.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ test('render a date in a string when format is time as kk:mm:ss', (t) => {
9797
t.ok(validate(JSON.parse(output)), 'valid schema')
9898
})
9999

100+
test('render a midnight time', (t) => {
101+
t.plan(3)
102+
103+
const schema = {
104+
title: 'a date in a string',
105+
type: 'string',
106+
format: 'time'
107+
}
108+
const midnight = new Date(new Date().setHours(24))
109+
110+
const validate = validator(schema)
111+
const stringify = build(schema)
112+
const output = stringify(midnight)
113+
114+
validate(JSON.parse(output))
115+
t.equal(validate.errors, null)
116+
117+
t.equal(output, `"${moment(midnight).format('HH:mm:ss')}"`)
118+
t.ok(validate(JSON.parse(output)), 'valid schema')
119+
})
120+
100121
test('verify padding for rendered date in a string when format is time', (t) => {
101122
t.plan(3)
102123

0 commit comments

Comments
 (0)