Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(datepickerPopup): correctly format to timezone
Browse files Browse the repository at this point in the history
- Format according to ngModelOptions timezone if specified

Closes #6159
Fixes #6105
Fixes #6146
Fixes #6147
  • Loading branch information
wesleycho committed Aug 15, 2016
1 parent 5597e2f commit fbd0845
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/datepickerPopup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $

this.init = function(_ngModel_) {
ngModel = _ngModel_;
ngModelOptions = _ngModel_.$options;
ngModelOptions = angular.isObject(_ngModel_.$options) ?
_ngModel_.$options :
{
timezone: null
};
closeOnDateSelection = angular.isDefined($attrs.closeOnDateSelection) ?
$scope.$parent.$eval($attrs.closeOnDateSelection) :
datepickerPopupConfig.closeOnDateSelection;
Expand Down Expand Up @@ -123,13 +127,13 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
value = new Date(value);
}

$scope.date = value;
$scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone);

return dateParser.filter($scope.date, dateFormat);
});
} else {
ngModel.$formatters.push(function(value) {
$scope.date = value;
$scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone);
return value;
});
}
Expand Down Expand Up @@ -181,7 +185,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $

$scope.isDisabled = function(date) {
if (date === 'today') {
date = new Date();
date = dateParser.fromTimezone(new Date(), ngModelOptions.timezone);
}

var dates = {};
Expand Down Expand Up @@ -328,7 +332,7 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
if (angular.isString(viewValue)) {
var date = parseDateString(viewValue);
if (!isNaN(date)) {
return date;
return dateParser.fromTimezone(date, ngModelOptions.timezone);
}
}

Expand Down

0 comments on commit fbd0845

Please sign in to comment.