From 692390104a4e1409fb99a1be69026af876ecac06 Mon Sep 17 00:00:00 2001
From: marquex <javi@arqex.com>
Date: Wed, 14 Oct 2015 19:32:14 +0200
Subject: [PATCH] Merges addition of strictParsing attribute.

---
 tests/datetime-spec.js |   22 ++++++++++++++++++++++
 DateTime.js            |    9 ++++++---
 README.md              |    1 +
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/DateTime.js b/DateTime.js
index b724a9a..8fe971e 100644
--- a/DateTime.js
+++ b/DateTime.js
@@ -31,7 +31,9 @@
 		// timeFormat: TYPES.string | TYPES.bool,
 		inputProps: TYPES.object,
 		viewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),
-		isValidDate: TYPES.func
+		isValidDate: TYPES.func,
+		open: TYPES.bool,
+		strictParsing: TYPES.bool
 	},
 
 	getDefaultProps: function() {
@@ -45,7 +47,8 @@
 			onBlur: nof,
 			onChange: nof,
 			timeFormat: true,
-			dateFormat: true
+			dateFormat: true,
+			strictParsing: true
 		};
 	},
 
@@ -259,7 +262,7 @@
 	},
 
 	localMoment: function( date, format ){
-		var m = moment( date, format );
+		var m = moment( date, format, this.props.strictParsing );
 		if( this.props.locale )
 			m.locale( this.props.locale );
 		return m;
diff --git a/README.md b/README.md
index 2c1a784..f462a8a 100644
--- a/README.md
+++ b/README.md
@@ -52,6 +52,7 @@
 | **renderDay** | function | DOM.td( day ) | Customize the way that the days are shown in the day picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, and must return a React component. See [appearance customization](#appearance-customization) |
 | **renderMonth** | function | DOM.td( month ) | Customize the way that the months are shown in the month picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, the `month` and the `year` to be shown, and must return a React component. See [appearance customization](#appearance-customization) |
 | **renderYear** | function | DOM.td( year ) | Customize the way that the years are shown in the year picker. The accepted function has the `selectedDate`, the current date and the default calculated `props` for the cell, the `year` to be shown, and must return a React component. See [appearance customization](#appearance-customization) |
+| **strictParsing** | boolean | false | Whether to use moment's [strict parsing](http://momentjs.com/docs/#/parsing/string-format/) when parsing input.
 
 ## i18n
 Different language and date formats are supported by react-datetime. React uses [moment.js](http://momentjs.com/) to format the dates, and the easiest way of changing the language of the calendar is [changing the moment.js locale](http://momentjs.com/docs/#/i18n/changing-locale/).
diff --git a/tests/datetime-spec.js b/tests/datetime-spec.js
index 50c3214..48a31cf 100644
--- a/tests/datetime-spec.js
+++ b/tests/datetime-spec.js
@@ -558,5 +558,27 @@
 		dt.input().value = '';
 		Utils.Simulate.change( dt.input() );
 	});
+
+	it( 'strictParsing=true', function( done ){
+		var invalidStrDate = strDate + 'x';
+		createDatetime({ defaultValue: '', strictParsing: true, onChange: function( updated ){
+			assert.equal( updated, invalidStrDate);
+			done();
+		}});
+
+		dt.input().value = invalidStrDate;
+		Utils.Simulate.change( dt.input() );
+	});
+
+	it( 'strictParsing=false', function( done ){
+		var invalidStrDate = strDate + 'x';
+		createDatetime({ defaultValue: '', strictParsing: false, onChange: function( updated ){
+			assert.equal( mDate.format('L LT'), updated.format('L LT') );
+			done();
+		}});
+
+		dt.input().value = invalidStrDate;
+		Utils.Simulate.change( dt.input() );
+	});
 });
 

--
Gitblit v1.9.3