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.

format throws when used on "Invalid Date" with advancedformat + timezone + utc

See original GitHub issue

Describe the bug When using the following format string on dayjs(null) the resulting date is “Invalid Date”

lll

When using the following string, dayjs throws

lll z

Thrown error:

Unhandled Runtime Error

RangeError: date value is not finite in DateTimeFormat.formatToParts()

dayjs(null).format('lll z')
           ^

Expected behavior dayjs should display “Invalid Date” and not throw an error

Information

  • Day.js Version v1.10.5
  • OS: Windows
  • Browser Firefox 89.0.2 (64-bit)
  • Time zone: EST

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SamuelPoulincommented, Jul 2, 2021

My bad, I should have mentionned that the z format option is only enabled with advancedFormat. Here’s a working example of the issue:

index.js

const dayjs = require("dayjs");

const utc = require("dayjs/plugin/utc");
const timezone = require("dayjs/plugin/timezone");
const advancedFormat = require("dayjs/plugin/advancedFormat");

dayjs.extend(utc)
dayjs.extend(timezone)
// dayjs.extend(advancedFormat) // When this is enabled, dayjs throws. When it's not, it outputs 'Invalid Date'.

console.log(dayjs(null).format('lll z'))
0reactions
imwh0imcommented, Jul 7, 2021

Merged complete

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trying to format date, always getting invalid date
When the user submits the form, I want to transform the date input to UTC using moment. However whatever I do with the...
Read more >
format throws when used on "Invalid Date" with ... - Issuehunt
format throws when used on "Invalid Date" with advancedformat + timezone + utc #1558 ; Describe the bug When using the following format...
Read more >
RangeError: invalid date - JavaScript - MDN Web Docs
The JavaScript exception "invalid date" occurs when a string leading to an invalid date has been provided to Date or Date.parse().
Read more >
Behavior and format of the Date and Time column
In Microsoft Dataverse, the Date and Time data type is used in many ... column values remain in the database in the UTC...
Read more >
Validation
Checks if the value could be parsed to a Date time and it is a valid date. The last two arguments format and...
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