Function `eachDayOfInterval` throws "RangeError: Invalid Interval" for interval that should be valid
See original GitHub issueI’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:
p.s. Happy to look into the code myself and PR a fix. Let me know!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For anyone still looking into this, creating a new Date instance inside the
startOfMonth
andendOfMonth
functions seems to work witheachDayOfInterval()
.const start = startOfMonth(new Date(someDate))
const end = endOfMonth(new Date(someDate))
eachDayOfInterval({ start: start, end: end })
Hope this helps!
I also just ran into this and fwiw it was only happening in Safari for me