Passing array value to format param to dayjs.utc() silently disables utc mode
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When an array is passed as the format argument to dayjs.utc(), UTC mode is not used: the date is parsed in the local timezone.
dayjs() accepts an array for the format parameter (with the customParseFormat plugin), so it’s easy to assume dayjs.utc() does too. With an array, dayjs.utc() does not throw; it silently parses in local time, which can cause subtle bugs (e.g. tests passing only when TZ=UTC).
To reproduce
```
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const customParseFormat = require('dayjs/plugin/customParseFormat');
dayjs.extend(utc);
dayjs.extend(customParseFormat);
// With a single format, result is UTC midnight (correct)
const single = dayjs.utc('1995-05-01', 'YYYY-MM-DD');
console.log(single.toISOString()); // '1995-05-01T00:00:00.000Z'
// With a format array, result is local midnight (incorrect)
const withArray = dayjs.utc('1995-05-01', ['YYYY-MM-DD', 'YYYY-M-D']);
console.log(withArray.toISOString()); // e.g. '1995-05-01T23:00:00.000Z' in UTC+1
```
Stackblitz link https://stackblitz.com/edit/dayjs-playground-8cua8kja?file=index.js
**Expected behavior**
Either:
- Support format arrays and parse in UTC (same semantics as single-format dayjs.utc(date, format)), or
- Reject array format (e.g. throw error)
**Likely cause**
In `customParseFormat`, when format is an array, the code uses `d.apply(this, args)` (the default constructor) instead of the UTC constructor, so each format is tried in local time.
**Information**
- Day.js Version 1.11.13
- OS: macos
- Browser: NA
- Time zone: NA
Contributor guide
Assessment
This issue has not been assessed yet.