Skip to content

Commit f413e1e

Browse files
benbcaimartijnrusschen
authored andcommitted
Make date parsing conform strictly to the date format. (Hacker0x01#1656)
* Make date parsing conform strictly to the date format. * Set awareOfUnicodeTokens to true. * Add strictParsing prop to enforce strict parsing. * undo indenting * undo indenting * Validate parsed date. * Validate parsed date. * Fix strict parsing when year is more than 4 digits.
1 parent 5e39708 commit f413e1e

File tree

6 files changed

+213
-86
lines changed

6 files changed

+213
-86
lines changed

docs-site/src/example_components.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import IncludeTimes from "./examples/include_times";
5252
import InjectTimes from "./examples/inject_times";
5353
import DontCloseOnSelect from "./examples/dont_close_onSelect";
5454
import RenderCustomHeader from "./examples/render_custom_header";
55+
import StrictParsing from "./examples/strict_parsing";
5556

5657
import "react-datepicker/dist/react-datepicker.css";
5758
import "./style.scss";
@@ -261,6 +262,10 @@ export default class exampleComponents extends React.Component {
261262
{
262263
title: "Custom header",
263264
component: <RenderCustomHeader />
265+
},
266+
{
267+
title: "Strict parsing",
268+
component: <StrictParsing />
264269
}
265270
];
266271

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import React from "react";
2+
import DatePicker from "react-datepicker";
3+
4+
export default class StrictParsing extends React.Component {
5+
constructor(props) {
6+
super(props);
7+
this.state = {
8+
startDate: new Date()
9+
};
10+
}
11+
12+
handleChange = date => {
13+
this.setState({
14+
startDate: date
15+
});
16+
};
17+
18+
render() {
19+
return (
20+
<div className="row">
21+
<pre className="column example__code">
22+
<code className="jsx">
23+
{`
24+
<DatePicker
25+
selected={this.state.startDate}
26+
onChange={this.handleChange}
27+
strictParsing
28+
/>
29+
`}
30+
</code>
31+
</pre>
32+
<div className="column">
33+
<DatePicker
34+
selected={this.state.startDate}
35+
onChange={this.handleChange}
36+
strictParsing
37+
/>
38+
</div>
39+
</div>
40+
);
41+
}
42+
}

0 commit comments

Comments
 (0)