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.

Parsing '2020-12-20T15:00:00+08' is broken in 1.10+

See original GitHub issue

Describe the bug

const day = require('dayjs');
console.log(`result:${dayjs('2020-12-20T15:00:00+08').format()}`);

In Day.js v1.9.8, we got result:2020-12-20T15:00:00+08:00. In Day.js v1.10.7, we got result:Invalid Date.

Is this a new feature or breaking change?

Expected behavior we expect the result is result:2020-12-20T15:00:00+08:00.

Information

  • Day.js: 1.10.7
  • OS: Ubuntu 20.04.1
  • Node.js: v.16.9.1
  • Time zone: Asia/Taipei (CST, +0800)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Mirochiucommented, Sep 22, 2021

It is difficult to check because the difference between versions is too large. Can you narrow the gap?

1.10.7 => 2021-09-10 1.9.8 => 2020-12-27

I’ve test v1.10.0. The result:Invalid Date.

0reactions
Mirochiucommented, May 27, 2022

Using an offset in a date/time string requires the customParseFormat’ plugin to work.

I am on dayjs 1.11.2 and this test works for me (the timezone and utc plugins are only used to format the result as CST):

import dayjs from 'dayjs'
import customParseFormat from 'plugin/customParseFormat'
import timezone from 'plugin/timezone'
import utc from 'plugin/utc'

dayjs.extend(customParseFormat)
dayjs.extend(utc)
dayjs.extend(timezone)


it('Parsing is broken', () => {
  const input = '2020-12-20T15:00:00+08'
  const format = 'YYYY-MM-DD[T]HH:mm:ssZ'
  const resultDayjs = dayjs(input, format)
  expect(resultDayjs.isValid()).toBe(true)
  expect(resultDayjs.tz('Asia/Taipei').format()).toBe('2020-12-20T15:00:00+08:00')
})

Thanks for your suggestion. It work well when we applied the plugin with time format.

Show my snippet in node.js below for anyone finding a solution.

const dayjs = require('dayjs')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
const format = 'YYYY-MM-DD[T]HH:mm:ssZ'
console.log(`result:${dayjs('2020-12-20T15:00:00+0800', format).format()}`);
console.log(`result:${dayjs('2020-12-20T15:00:00+08', format).format()}`);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Regions file parsing broken #1215 - samtools/bcftools - GitHub
Regions file parsing broken #1215 ... bcftools 1.10.2 ... Same issue if I use -T option, tab-separated file is not parsed properly.
Read more >
Parsing broken XML - java - Stack Overflow
The only way I found to fix this was to tokenize the whole input and rebuild it piece by piece filtering out the...
Read more >
Json.Decode.Broken - Elm Packages
Parse the given JSON string. Errors come straight from elm/parser and may not be super useful. It may be worth changing this parser...
Read more >
An Artisan Guide to Building Broken C Parsers - Blog
The cases examined here are interesting because a sufficiently advanced compiler will need to consider them at parse time.
Read more >
Most vexing parse is broken : CPP-11676 - YouTrack
CLion does not parse function declarations correctly if they contain user-defined types or typedefs. This happens when the parameter of the declared ...
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