This repository was archived by the owner on Sep 5, 2024. It is now read-only.
File tree 3 files changed +21
-7
lines changed
src/components/datepicker/js
3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change 174
174
/**
175
175
* The date that is currently focused or showing in the calendar. This will initially be set
176
176
* to the ng-model value if set, otherwise to today. It will be updated as the user navigates
177
- * to other months. The cell corresponding to the displayDate does not necesarily always have
177
+ * to other months. The cell corresponding to the displayDate does not necessarily always have
178
178
* focus in the document (such as for cases when the user is scrolling the calendar).
179
179
* @type {Date }
180
180
*/
Original file line number Diff line number Diff line change 339
339
*/
340
340
this . $scope = $scope ;
341
341
342
- /** @type {Date } */
342
+ /**
343
+ * This holds the model that will be used by the calendar.
344
+ * @type {Date|null|undefined }
345
+ */
343
346
this . date = null ;
344
347
345
348
/** @type {boolean } */
631
634
* @param {Date= } opt_date Date to check. If not given, defaults to the datepicker's model value.
632
635
*/
633
636
DatePickerCtrl . prototype . updateErrorState = function ( opt_date ) {
634
- var date = opt_date || this . date ;
637
+ var date ;
638
+ if ( opt_date ) {
639
+ date = new Date ( opt_date . valueOf ( ) ) ;
640
+ } else {
641
+ date = angular . copy ( this . ngModelCtrl . $modelValue ) ;
642
+ }
635
643
636
644
// Clear any existing errors to get rid of anything that's no longer relevant.
637
645
this . clearErrorState ( ) ;
840
848
841
849
/**
842
850
* Open the floating calendar pane.
843
- * @param {Event } event
851
+ * @param {MouseEvent|KeyboardEvent|{target: HTMLInputElement} } event
844
852
*/
845
853
DatePickerCtrl . prototype . openCalendarPane = function ( event ) {
846
854
if ( ! this . isCalendarOpen && ! this . isDisabled && ! this . inputFocusedOnWindowBlur ) {
901
909
}
902
910
}
903
911
904
- function reset ( ) {
912
+ function reset ( ) {
905
913
self . isCalendarOpen = self . isOpen = false ;
906
914
}
907
915
} ;
916
924
// Use a timeout in order to allow the calendar to be rendered, as it is gated behind an ng-if.
917
925
var self = this ;
918
926
this . $mdUtil . nextTick ( function ( ) {
919
- self . getCalendarCtrl ( ) . focusDate ( ) ;
927
+ self . getCalendarCtrl ( ) . focusDate ( self . date ) ;
920
928
} , false ) ;
921
929
} ;
922
930
1007
1015
var self = this ;
1008
1016
var timezone = this . $mdUtil . getModelOption ( this . ngModelCtrl , 'timezone' ) ;
1009
1017
1018
+ // Update the model used by the calendar.
1010
1019
if ( this . dateUtil . isValidDate ( value ) && timezone != null && value . getTimezoneOffset ( ) >= 0 ) {
1011
1020
this . date = this . dateUtil . removeLocalTzAndReparseDate ( value ) ;
1012
1021
} else {
Original file line number Diff line number Diff line change @@ -153,7 +153,12 @@ describe('md-datepicker', function() {
153
153
createDatepickerInstance (
154
154
'<md-datepicker ng-model="myDate" ng-model-options="modelOptions"></md-datepicker>' ) ;
155
155
156
- expect ( controller . locale . formatDate ) . toHaveBeenCalledWith ( pageScope . myDate , 'UTC' ) ;
156
+ // If running in a GMT+X timezone, formatDate will not be called with a timezone argument.
157
+ if ( pageScope . myDate . getTimezoneOffset ( ) < 0 ) {
158
+ expect ( controller . locale . formatDate ) . toHaveBeenCalledWith ( pageScope . myDate ) ;
159
+ } else {
160
+ expect ( controller . locale . formatDate ) . toHaveBeenCalledWith ( pageScope . myDate , 'UTC' ) ;
161
+ }
157
162
} ) ;
158
163
159
164
it ( 'should allow for the locale to be overwritten on a specific element' , function ( ) {
You can’t perform that action at this time.
0 commit comments