Parsing with format object parameter doesn't work
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
I'm using the following plugins:
```ts
import * as customParseFormat from 'dayjs/plugin/customParseFormat';
import * as weekday from 'dayjs/plugin/weekday';
import * as localizedFormat from 'dayjs/plugin/localizedFormat';
import * as DAYJS_LOCALE_DE from 'dayjs/locale/de';
dayjs.extend(customParseFormat);
dayjs.extend(weekday);
dayjs.extend(localizedFormat);
dayjs.locale(DAYJS_LOCALE_DE);
```
The [TypeScript declarations](https://github.com/iamkun/dayjs/blob/dev/types/index.d.ts#L5-L14) (extract below) suggest that the `dayjs()` function accepts the second parameter in the object form `{ locale?: string, format?: string, utc?: boolean }`.
```ts
declare function dayjs (date?: dayjs.ConfigType): dayjs.Dayjs
declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, strict?: boolean): dayjs.Dayjs
declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean): dayjs.Dayjs
declare namespace dayjs {
export type ConfigType = string | number | Date | Dayjs
export type OptionType = { locale?: string, format?: string, utc?: boolean } | string | string[]
...
}
```
However, calling `dayjs('8. Dez 2020 15:22', { format: 'D. MMM YYYY HH:mm'})` returns an invalid date whereas `dayjs('8. Dez 2020 15:22', 'D. MMM YYYY HH:mm')` returns a parsed date.
**Expected behavior**
Calling `dayjs('8. Dez 2020 15:22', { format: 'D. MMM YYYY HH:mm'})` returns a parsed date.
**Information**
- Day.js Version 1.9.7
- OS: Windows
- Browser Firefox 84, Chrome 87
- Time zone: GMT+1
Contributor guide
Research direction
Start with the overloads in types/index.d.ts and the customParseFormat plugin entry point, then reproduce the German-locale example using the object-form format parameter. Compare it with the string-format call and add or update a focused parsing test; done means the object form returns a valid parsed date.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100