@@ -1149,10 +1149,10 @@ function createDateInputType(type, regexp, parseDate, format) {
11491149 } ) ;
11501150
11511151 ctrl . $formatters . push ( function ( value ) {
1152- if ( ! ctrl . $isEmpty ( value ) ) {
1153- if ( ! isDate ( value ) ) {
1154- throw $ngModelMinErr ( 'datefmt' , 'Expected `{0}` to be a date' , value ) ;
1155- }
1152+ if ( value && ! isDate ( value ) ) {
1153+ throw $ngModelMinErr ( 'datefmt' , 'Expected `{0}` to be a date' , value ) ;
1154+ }
1155+ if ( isValidDate ( value ) ) {
11561156 previousDate = value ;
11571157 if ( previousDate && timezone === 'UTC' ) {
11581158 var timezoneOffset = 60000 * previousDate . getTimezoneOffset ( ) ;
@@ -1161,14 +1161,14 @@ function createDateInputType(type, regexp, parseDate, format) {
11611161 return $filter ( 'date' ) ( value , format , timezone ) ;
11621162 } else {
11631163 previousDate = null ;
1164+ return '' ;
11641165 }
1165- return '' ;
11661166 } ) ;
11671167
11681168 if ( isDefined ( attr . min ) || attr . ngMin ) {
11691169 var minVal ;
11701170 ctrl . $validators . min = function ( value ) {
1171- return ctrl . $isEmpty ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
1171+ return ! isValidDate ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
11721172 } ;
11731173 attr . $observe ( 'min' , function ( val ) {
11741174 minVal = parseObservedDateValue ( val ) ;
@@ -1179,18 +1179,18 @@ function createDateInputType(type, regexp, parseDate, format) {
11791179 if ( isDefined ( attr . max ) || attr . ngMax ) {
11801180 var maxVal ;
11811181 ctrl . $validators . max = function ( value ) {
1182- return ctrl . $isEmpty ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
1182+ return ! isValidDate ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
11831183 } ;
11841184 attr . $observe ( 'max' , function ( val ) {
11851185 maxVal = parseObservedDateValue ( val ) ;
11861186 ctrl . $validate ( ) ;
11871187 } ) ;
11881188 }
1189- // Override the standard $isEmpty to detect invalid dates as well
1190- ctrl . $isEmpty = function ( value ) {
1189+
1190+ function isValidDate ( value ) {
11911191 // Invalid Date: getTime() returns NaN
1192- return ! value || ( value . getTime && value . getTime ( ) !== value . getTime ( ) ) ;
1193- } ;
1192+ return value && ! ( value . getTime && value . getTime ( ) !== value . getTime ( ) ) ;
1193+ }
11941194
11951195 function parseObservedDateValue ( val ) {
11961196 return isDefined ( val ) ? ( isDate ( val ) ? val : parseDate ( val ) ) : undefined ;
0 commit comments