@@ -679,7 +679,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
679
679
680
680
// Detect changes in the view from the text box
681
681
ngModel . $viewChangeListeners . push ( function ( ) {
682
- scope . date = dateParser . parse ( ngModel . $viewValue , dateFormat , scope . date ) ;
682
+ scope . date = parseDateString ( ngModel . $viewValue ) ;
683
683
} ) ;
684
684
685
685
element . bind ( 'keydown' , inputKeydownBind ) ;
@@ -797,6 +797,19 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
797
797
return string . replace ( / ( [ A - Z ] ) / g, function ( $1 ) { return '-' + $1 . toLowerCase ( ) ; } ) ;
798
798
}
799
799
800
+ function parseDateString ( viewValue ) {
801
+ var date = dateParser . parse ( viewValue , dateFormat , scope . date ) ;
802
+ if ( isNaN ( date ) ) {
803
+ for ( var i = 0 ; i < altInputFormats . length ; i ++ ) {
804
+ date = dateParser . parse ( viewValue , altInputFormats [ i ] , scope . date ) ;
805
+ if ( ! isNaN ( date ) ) {
806
+ return date ;
807
+ }
808
+ }
809
+ }
810
+ return date ;
811
+ }
812
+
800
813
function parseDate ( viewValue ) {
801
814
if ( angular . isNumber ( viewValue ) ) {
802
815
// presumably timestamp to date object
@@ -812,15 +825,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
812
825
}
813
826
814
827
if ( angular . isString ( viewValue ) ) {
815
- var date = dateParser . parse ( viewValue , dateFormat , scope . date ) ;
816
- if ( isNaN ( date ) ) {
817
- for ( var i = 0 ; i < altInputFormats . length ; i ++ ) {
818
- date = dateParser . parse ( viewValue , altInputFormats [ i ] , scope . date ) ;
819
- if ( ! isNaN ( date ) ) {
820
- break ;
821
- }
822
- }
823
- }
828
+ var date = parseDateString ( viewValue ) ;
824
829
if ( isNaN ( date ) ) {
825
830
return undefined ;
826
831
}
@@ -851,16 +856,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
851
856
}
852
857
853
858
if ( angular . isString ( value ) ) {
854
- var date = dateParser . parse ( value , dateFormat ) ;
855
- if ( isNaN ( date ) ) {
856
- for ( var i = 0 ; i < altInputFormats . length ; i ++ ) {
857
- date = dateParser . parse ( value , altInputFormats [ i ] ) ;
858
- if ( ! isNaN ( date ) ) {
859
- break ;
860
- }
861
- }
862
- }
863
- return ! isNaN ( date ) ;
859
+ return ! isNaN ( parseDateString ( viewValue ) ) ;
864
860
}
865
861
866
862
return false ;
0 commit comments