I've been building an demo with React and came across react-intl. I tried to use the FormattedDate component with a 'value' that is returned from an API call and is stored in 'this.state'
However the page fails to load and the console shows: RangeError: Provided date is not in valid range, the code is below.
index.js
ReactDOM.render(
<IntlProvider locale='en'>
<Router>
<Route path="/" component={App}>
<IndexRoute component={Login} />
<Route path="bookings" component={Bookings} />
<Route path="bookings/:id" component={BookingDetail} />
<Route path="create" component={BookingCreate} />
</Route>
</Router>
</IntlProvider>,
document.getElementById('react-container')
);
and in my component's render I Have,
render() {
return (
<FormattedDate value={new Date(this.state.booking.checkIn)} day="numeric" month="long" year="numeric" />
)
}
In the code we see that the component uses Intl.DateTimeFormat.prototype.format to produce the formatted date, but when I do the same in the Node repl
var date = '2015-10-30T23:53:28.879Z'
console.log(new Intl.DateTimeFormat().format(new Date(date)));
10/30/2015 //It produces the correct output
Any idea why this is happening? I've tried also tried assigning the bare string as the 'value', as well as (new Date(date.parse(this.state.booking.checkIn)
, but the all produce the range error.