@@ -1145,10 +1145,10 @@ function createDateInputType(type, regexp, parseDate, format) {
1145
1145
} ) ;
1146
1146
1147
1147
ctrl . $formatters . push ( function ( value ) {
1148
- if ( ! ctrl . $isEmpty ( value ) ) {
1149
- if ( ! isDate ( value ) ) {
1150
- throw $ngModelMinErr ( 'datefmt' , 'Expected `{0}` to be a date' , value ) ;
1151
- }
1148
+ if ( value && ! isDate ( value ) ) {
1149
+ throw $ngModelMinErr ( 'datefmt' , 'Expected `{0}` to be a date' , value ) ;
1150
+ }
1151
+ if ( isValidDate ( value ) ) {
1152
1152
previousDate = value ;
1153
1153
if ( previousDate && timezone === 'UTC' ) {
1154
1154
var timezoneOffset = 60000 * previousDate . getTimezoneOffset ( ) ;
@@ -1157,14 +1157,14 @@ function createDateInputType(type, regexp, parseDate, format) {
1157
1157
return $filter ( 'date' ) ( value , format , timezone ) ;
1158
1158
} else {
1159
1159
previousDate = null ;
1160
+ return '' ;
1160
1161
}
1161
- return '' ;
1162
1162
} ) ;
1163
1163
1164
1164
if ( isDefined ( attr . min ) || attr . ngMin ) {
1165
1165
var minVal ;
1166
1166
ctrl . $validators . min = function ( value ) {
1167
- return ctrl . $isEmpty ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
1167
+ return ! isValidDate ( value ) || isUndefined ( minVal ) || parseDate ( value ) >= minVal ;
1168
1168
} ;
1169
1169
attr . $observe ( 'min' , function ( val ) {
1170
1170
minVal = parseObservedDateValue ( val ) ;
@@ -1175,18 +1175,18 @@ function createDateInputType(type, regexp, parseDate, format) {
1175
1175
if ( isDefined ( attr . max ) || attr . ngMax ) {
1176
1176
var maxVal ;
1177
1177
ctrl . $validators . max = function ( value ) {
1178
- return ctrl . $isEmpty ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
1178
+ return ! isValidDate ( value ) || isUndefined ( maxVal ) || parseDate ( value ) <= maxVal ;
1179
1179
} ;
1180
1180
attr . $observe ( 'max' , function ( val ) {
1181
1181
maxVal = parseObservedDateValue ( val ) ;
1182
1182
ctrl . $validate ( ) ;
1183
1183
} ) ;
1184
1184
}
1185
- // Override the standard $isEmpty to detect invalid dates as well
1186
- ctrl . $isEmpty = function ( value ) {
1185
+
1186
+ function isValidDate ( value ) {
1187
1187
// Invalid Date: getTime() returns NaN
1188
- return ! value || ( value . getTime && value . getTime ( ) !== value . getTime ( ) ) ;
1189
- } ;
1188
+ return value && ! ( value . getTime && value . getTime ( ) !== value . getTime ( ) ) ;
1189
+ }
1190
1190
1191
1191
function parseObservedDateValue ( val ) {
1192
1192
return isDefined ( val ) ? ( isDate ( val ) ? val : parseDate ( val ) ) : undefined ;
0 commit comments