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.

Function `eachDayOfInterval` throws "RangeError: Invalid Interval" for interval that should be valid

See original GitHub issue

I’m giving the eachDayOfInterval function an input of two JavaScript Date objects that should be valid. They are the outputs of other date-fns functions startOfWeek and endOfWeek. I get the expected output from the eachDayOfInterval function, but because it throws an error, my code execution stops.

Also, I might be wrong in my report (I’m a new programmer, so I’m not super confident in this).

Here’s an example code:

const someDate = new Date()
const startDateThisWeek = startOfWeek(someDate)
const endDateThisWeek = endOfWeek(someDate)
const arrayOfDaysThisWeek = eachDayOfInterval({ start: startDateThisWeek, end: endDateThisWeek })
// RangeError: Invalid interval

console.log(arrayOfDaysThisWeek)

/*
[
      2020-01-26T08:00:00.000Z,
      2020-01-27T08:00:00.000Z,
      2020-01-28T08:00:00.000Z,
      2020-01-29T08:00:00.000Z,
      2020-01-30T08:00:00.000Z,
      2020-01-31T08:00:00.000Z,
      2020-02-01T08:00:00.000Z
    ]
*/

Here’s a screenshot of my tests:

image

p.s. Happy to look into the code myself and PR a fix. Let me know!

Issue Analytics

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

github_iconTop GitHub Comments

4reactions
tonyQuigcommented, Mar 24, 2021

For anyone still looking into this, creating a new Date instance inside the startOfMonth and endOfMonth functions seems to work with eachDayOfInterval().

const start = startOfMonth(new Date(someDate)) const end = endOfMonth(new Date(someDate)) eachDayOfInterval({ start: start, end: end })

Hope this helps!

1reaction
Tzinov15commented, Apr 18, 2021

I also just ran into this and fwiw it was only happening in Safari for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid time value while setting custom date to DatePicker of ...
It seems your date is in string format. Datepicker don't accept string date. You need to parse the string date to actual date...
Read more >
A brand new website interface for an even better experience!
Function `eachDayOfInterval` throws "RangeError: Invalid Interval" for interval that should be valid.
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 >
client/node_modules/date-fns/CHANGELOG.md - GitLab
When a string is passed, it will result in an unexpected result ( Invalid Date ... All these functions throw RangeError if the...
Read more >
laudatio-repository - node_modules - date-fns - GitLab
All these functions throw RangeError if the start of the interval is after ... for numbers and Invalid Date for dates), an invalid...
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