@@ -679,7 +679,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
679679
680680 // Detect changes in the view from the text box
681681 ngModel . $viewChangeListeners . push ( function ( ) {
682- scope . date = dateParser . parse ( ngModel . $viewValue , dateFormat , scope . date ) ;
682+ scope . date = parseDateString ( ngModel . $viewValue ) ;
683683 } ) ;
684684
685685 element . bind ( 'keydown' , inputKeydownBind ) ;
@@ -797,6 +797,19 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
797797 return string . replace ( / ( [ A - Z ] ) / g, function ( $1 ) { return '-' + $1 . toLowerCase ( ) ; } ) ;
798798 }
799799
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+
800813 function parseDate ( viewValue ) {
801814 if ( angular . isNumber ( viewValue ) ) {
802815 // presumably timestamp to date object
@@ -812,15 +825,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
812825 }
813826
814827 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 ) ;
824829 if ( isNaN ( date ) ) {
825830 return undefined ;
826831 }
@@ -851,16 +856,7 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
851856 }
852857
853858 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 ) ) ;
864860 }
865861
866862 return false ;
0 commit comments