Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/plugin/customParseFormat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export default (o, C, d) => {
args[1] = format[i - 1]
const result = d.apply(this, args)
if (result.isValid()) {
this.$d = result.$d
this.$d = utc
? parseFormattedInput(date, format[i - 1], utc, d)
: result.$d
this.$L = result.$L
this.init()
break
Expand Down
20 changes: 20 additions & 0 deletions test/plugin/utc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ describe('UTC with customParseFormat', () => {
expect(instant.format()).toBe('2011-02-02T03:04:05Z')
expect(instant.format()).toBe(momentInstant.format())
})

it('Array format - parses in UTC, not local time', () => {
dayjs.extend(customParseFormat)
const date = '1995-05-01'
const formats = ['YYYY-MM-DD', 'YYYY-M-D']
const result = dayjs.utc(date, formats)
expect(result.isValid()).toBe(true)
expect(result.toISOString()).toBe('1995-05-01T00:00:00.000Z')
expect(result.isUTC()).toBe(true)
})

it('Array format - second format matches, parsed in UTC', () => {
dayjs.extend(customParseFormat)
const date = '1995-5-1'
const formats = ['YYYY-MM-DD', 'YYYY-M-D']
const result = dayjs.utc(date, formats)
expect(result.isValid()).toBe(true)
expect(result.toISOString()).toBe('1995-05-01T00:00:00.000Z')
expect(result.isUTC()).toBe(true)
})
})

describe('UTC Offset', () => {
Expand Down