|
990 | 990 | */ |
991 | 991 | DatePickerCtrl.prototype.setModelValue = function(value) { |
992 | 992 | var timezone = this.$mdUtil.getModelOption(this.ngModelCtrl, 'timezone'); |
993 | | - this.ngModelCtrl.$setViewValue(this.ngDateFilter(value, 'yyyy-MM-dd', timezone), 'default'); |
| 993 | + // Using the timezone when the offset is negative (GMT+X) causes the previous day to be |
| 994 | + // set as the model value here. This check avoids that. |
| 995 | + if (timezone == null || value.getTimezoneOffset() < 0) { |
| 996 | + this.ngModelCtrl.$setViewValue(this.ngDateFilter(value, 'yyyy-MM-dd'), 'default'); |
| 997 | + } else { |
| 998 | + this.ngModelCtrl.$setViewValue(this.ngDateFilter(value, 'yyyy-MM-dd', timezone), 'default'); |
| 999 | + } |
994 | 1000 | }; |
995 | 1001 |
|
996 | 1002 | /** |
|
1001 | 1007 | var self = this; |
1002 | 1008 | var timezone = this.$mdUtil.getModelOption(this.ngModelCtrl, 'timezone'); |
1003 | 1009 |
|
1004 | | - if (this.dateUtil.isValidDate(value) && timezone != null) { |
| 1010 | + if (this.dateUtil.isValidDate(value) && timezone != null && value.getTimezoneOffset() >= 0) { |
1005 | 1011 | this.date = this.dateUtil.removeLocalTzAndReparseDate(value); |
1006 | 1012 | } else { |
1007 | 1013 | this.date = value; |
1008 | 1014 | } |
1009 | | - this.inputElement.value = this.locale.formatDate(value, timezone); |
| 1015 | + // Using the timezone when the offset is negative (GMT+X) causes the previous day to be |
| 1016 | + // used here. This check avoids that. |
| 1017 | + if (timezone == null || value.getTimezoneOffset() < 0) { |
| 1018 | + this.inputElement.value = this.locale.formatDate(value); |
| 1019 | + } else { |
| 1020 | + this.inputElement.value = this.locale.formatDate(value, timezone); |
| 1021 | + } |
1010 | 1022 | this.mdInputContainer && this.mdInputContainer.setHasValue(!!value); |
1011 | 1023 | this.resizeInputElement(); |
1012 | 1024 | // This is often called from the $formatters section of the $validators pipeline. |
|
0 commit comments