iamkun / iamkun/dayjs

Format to name of day, week, month: "Cannot read properties of undefined"

Open
#2,523 1 comment 1 reaction 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.