dayjs icon indicating copy to clipboard operation
dayjs copied to clipboard

Parsing dates with a named day of the week fails.

Open Orbyt opened this issue 5 years ago • 5 comments

Describe the bug Parsing dates with a named day of the week fails. However, switching the function to call moment works as expected.

const dayjs = require('dayjs')
// Multiple plugins were tested.
let weekday = require('dayjs/plugin/weekday')
let customParseFormat = require('dayjs/plugin/customParseFormat')
let localeData = require('dayjs/plugin/localeData')
let localizedFormat = require('dayjs/plugin/localizedFormat')
let updateLocale = require('dayjs/plugin/updateLocale')
let utc = require('dayjs/plugin/utc')
dayjs.extend(weekday)
dayjs.extend(localeData)
dayjs.extend(customParseFormat)
dayjs.extend(localizedFormat)
dayjs.extend(updateLocale)
dayjs.extend(utc)

// Prints `false`.
console.log(dayjs('Wednesday, December 30th 2020 (6:00 pm)', 'dddd, MMMM Do YYYY (h:mm a)').isValid()) 

// Prints `true`.
var moment = require('moment');
console.log(moment('Wednesday, December 30th 2020 (6:00 pm)', 'dddd, MMMM Do YYYY (h:mm a)').isValid()) 

Information

  • Day.js Version 1.9.8
  • OS: macOS - Node.js
  • Time zone: Pacific

Orbyt avatar Dec 31 '20 07:12 Orbyt

https://github.com/iamkun/dayjs/pull/576 appears to have been an attempt to fix a similar issue, but it was never merged.

Orbyt avatar Dec 31 '20 19:12 Orbyt

I have the same problem. Any news on this fix? Or is the best way to avoid using dddd with customParseFormat?

ssergeyyy avatar Dec 15 '21 14:12 ssergeyyy

I have the same problem. Is there anyway to validate weekday format

huypxgear avatar May 18 '22 16:05 huypxgear

You have 2 problems

  1. 'dddd' is similar to the issue #1802 - dayjs (and moment too) don't have a dddd parsing format
    This should be a feature request
  2. and the commas in the format are similar to the issue #1913 - dayjs does not accept the comma as a separator character.
    This would be fixed with PR #1913

BePo65 avatar May 31 '22 10:05 BePo65

Hi @iamkun, Any news on this please ? :pray: Thank you

KaKi87 avatar Apr 12 '25 15:04 KaKi87