@@ -1149,10 +1149,10 @@ function createDateInputType(type, regexp, parseDate, format) {
1149
1149
} ) ;
1150
1150
1151
1151
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 ) ) {
1156
1156
previousDate = value ;
1157
1157
if ( previousDate && timezone === 'UTC' ) {
1158
1158
var timezoneOffset = 60000 * previousDate . getTimezoneOffset ( ) ;
@@ -1161,14 +1161,14 @@ function createDateInputType(type, regexp, parseDate, format) {
1161
1161
return $filter ( 'date' ) ( value , format , timezone ) ;
1162
1162
} else {
1163
1163
previousDate = null ;
1164
+ return '' ;
1164
1165
}
1165
- return '' ;
1166
1166
} ) ;
1167
1167
1168
1168
if ( isDefined ( attr . min ) || attr . ngMin ) {
1169
1169
var minVal ;
1170
1170
ctrl . $validators . min = function ( value ) {
1171
- return ctrl . $isEmpty ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
1171
+ return ! isValidDate ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
1172
1172
} ;
1173
1173
attr . $observe ( 'min' , function ( val ) {
1174
1174
minVal = parseObservedDateValue ( val ) ;
@@ -1179,18 +1179,18 @@ function createDateInputType(type, regexp, parseDate, format) {
1179
1179
if ( isDefined ( attr . max ) || attr . ngMax ) {
1180
1180
var maxVal ;
1181
1181
ctrl . $validators . max = function ( value ) {
1182
- return ctrl . $isEmpty ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
1182
+ return ! isValidDate ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
1183
1183
} ;
1184
1184
attr . $observe ( 'max' , function ( val ) {
1185
1185
maxVal = parseObservedDateValue ( val ) ;
1186
1186
ctrl . $validate ( ) ;
1187
1187
} ) ;
1188
1188
}
1189
- // Override the standard $isEmpty to detect invalid dates as well
1190
- ctrl . $isEmpty = function ( value ) {
1189
+
1190
+ function isValidDate ( value ) {
1191
1191
// 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
+ }
1194
1194
1195
1195
function parseObservedDateValue ( val ) {
1196
1196
return isDefined ( val ) ? ( isDate ( val ) ? val : parseDate ( val ) ) : undefined ;
0 commit comments