question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

customParseFormat strict mode bug

See original GitHub issue

Describe the bug Using the format string “YYYY-MM-DD HH:mm:ss ZZ”, parsing certain strings returns Invalid Date when it should return a date:

var format = "YYYY-MM-DD HH:mm:ss ZZ";
var ok = dayjs("2018-03-01 00:01:00 +0000", format, true);
var bad = dayjs("2018-04-01 00:01:00 +0000", format, true);

where bad is:

{
  "$D": 1
  "$H": 1
  "$L": "en"
  "$M": 3
  "$W": 0
  "$d": Invalid Date
  "$m": 1
  "$ms": 0
  "$s": 0
  "$u": undefined
  "$y": 2018
}

The parsing is successful if strict mode is not used. The problem seems to be in the customParseFormat.js line:

      if (isStrict && date !== this.format(format)) {

where the date that the plugin has parsed is not matching the default output from dayjs.format(). In the above case:

"2018-04-01 00:01:00 +0000" !== "2018-04-01 01:01:00 +0100"

but the same bug will effect parsing any date where the timezone doesn’t match whatever local timezone/dst dayjs uses. eg. “2018-03-01 00:01:00 +0600”, “2018-04-01 00:01:00 -0200”, etc.

Expected behavior bad should be a valid date object.

Information

  • Day.js Version: v1.8.28
  • OS: Windows 7
  • Browser: Firefox 77, Chrome 83
  • Time zone: UTC+00:00 DST (British Summer Time)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

12reactions
iamkuncommented, Sep 17, 2020

Bug confirmed. Strict mode does not work good with parsing timezone (ZZ)

I’m looking for a way to solve it.

7reactions
ivansiedercommented, Oct 13, 2021

@iamkun is there anything else we can do to help get this pull request merged?

Read more comments on GitHub >

github_iconTop Results From Across the Web

customParseFormat strict mode bug #929 - Issuehunt
Rework how strict parsing in customParseFormat works by giving each segment expression information on how to enforce a strict format. posted by DDoerner...
Read more >
iamkun/dayjs - Gitter
Hi all, is there anyway to have a strict mode. import dayjs from 'dayjs'; import customParseFormat from 'dayjs/plugin/customParseFormat'; dayjs('2020-13-32' ...
Read more >
dayjs/CHANGELOG and dayjs Releases (Page 5) | LibHunt
customParseFormat plugin to parse comma as a separator character (#1913) (41b1405) ... fix customParseFormat plugin strict mode parse meridiem bug (#1321) ...
Read more >
CHANGELOG.md | dayjs@v1.10.5 - Deno
fix customParseFormat plugin strict mode parse meridiem bug (#1321) (e49eeef) · fix weekYear plugin missing locale bug (#1319) (344bdc0), closes #1304 · update ......
Read more >
Format custom date using dayjs without using ... - Stack Overflow
The part that I'm stuck on is that converting an Dayjs object with ISO8601 under strict mode as momentjs does. At first, I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found