Format to name of day, week, month: "Cannot read properties of undefined"
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.8k
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Formatting datetime with name of week, name of month, etc. throws an error.
dayjs().format('ddd')
TypeError: Cannot read properties of undefined (reading '4')
at h (/Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js:1:5023)
at /Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js:1:5544
at /Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js:1:5920
at String.replace (<anonymous>)
at M.m.format (/Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/dayjs.min.js:1:5160)
at M.u.format (/Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/dayjs@1.11.10/node_modules/dayjs/plugin/utc.js:1:1655)
at /Users/suah/Projects/Javascripts/tcl/packages/common/tests/date/comparator.test.ts:27:25
at file:///Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/@vitest+runner@0.34.6/node_modules/@vitest/runner/dist/index.js:135:14
at file:///Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/@vitest+runner@0.34.6/node_modules/@vitest/runner/dist/index.js:58:26
at runTest (file:///Users/suah/Projects/Javascripts/tcl/node_modules/.pnpm/@vitest+runner@0.34.6/node_modules/@vitest/runner/dist/index.js:663:17)
Expected behavior
Should return a string with the name of the week.
Information
- Day.js Version 1.11.10
- OS: Mac 13.4.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure from packages/common/tests/date/comparator.test.ts with Day.js 1.11.10 and the utc plugin. Trace formatting for the ddd token through the UTC and format paths, then confirm the fix by verifying that weekday and related name-based tokens return strings instead of throwing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100