iamkun / dayjs

⏰ Day.js 2kB immutable date-time library alternative to Moment.js with the same modern API
https://day.js.org
MIT License
47k stars 2.3k forks source link

Parsing dates with a named day of the week fails. #1296

Open Orbyt opened 3 years ago

Orbyt commented 3 years ago

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

Orbyt commented 3 years ago

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

ssergeyyy commented 2 years ago

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

huypxgear commented 2 years ago

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

BePo65 commented 2 years ago

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