Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect date parsing when format is 'MMM-YY' #1902

Open
mpycio opened this issue May 16, 2022 · 3 comments
Open

Incorrect date parsing when format is 'MMM-YY' #1902

mpycio opened this issue May 16, 2022 · 3 comments

Comments

@mpycio
Copy link

mpycio commented May 16, 2022

Describe the bug
'Apr-22' is getting parsed as 22/04/2001, despite providing parse format as 'MMM-YY', https://jsfiddle.net/Lhv5fpyw/4/

Expected behavior
Date should be parsed correctly as 01/04/2022.

Information

  • Day.js Version 1.11.2
  • OS: OSX
  • Browser : Chrome 101
  • Time zone: BST
@astoilkov
Copy link

I have the same issue. Posting my dummy workaround here:

function fixDayjs(input: string): Dayjs | undefined {
  const date = dayjs(input)
  
  if (date.isValid()) {
    // https://github.com/iamkun/dayjs/issues/1902
    // https://github.com/iamkun/dayjs/issues/1251
    if (date.year() === 2001 && !input.split(' ').includes('2001')) {
      return date.set('year', dayjs().year())
    }

    return date
  }

  return undefined
}

@joeyipjoeyip
Copy link

I have another incorrect parsing bug

Describe the bug
Converting "173000123" with format "HHmmssSSS" to get Unix timestamp in milliseconds returns a negative value, which when parsed back, returns "Mon Dec 12 1729 03:00:00 GMT+0736", https://jsfiddle.net/joeyip/8t2jd1bm/

Expected behavior
The time part should be 17:30:00

Information

  • Day.js Version 1.11.2
  • OS: Windows 10
  • Browser : Firefox 91.9.1esr
  • Time zone: GMT+8

@BePo65
Copy link
Contributor

BePo65 commented Jun 3, 2022

Would be fixed with pr #1914

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants