Skip to content

Commit

Permalink
T1044-0 Fix a lot of Datepicker popup issues - see comments
Browse files Browse the repository at this point in the history
  • Loading branch information
noullet committed Apr 5, 2018
1 parent b17b1f9 commit 6b50b31
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1641,8 +1641,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
var model = ngModelCtrl.$viewValue ? new Date(ngModelCtrl.$viewValue) : null;
model = dateParser.fromTimezone(model, ngModelOptions.timezone);
var today = new Date();
today = dateParser.fromTimezone(today, ngModelOptions.timezone);
var time = this.compare(date, today);
var time = this.compare(date, today); // Customization: don't convert browser date, as we compare it with a date converted to browser timezone
var dt = {
date: date,
label: dateParser.filter(date, format),
Expand Down Expand Up @@ -2802,6 +2801,11 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
$scope.datepickerOptions = {};
}

// Customization: Pass ngModelOptions to UibDatepickerController
if (!$scope.datepickerOptions.ngModelOptions && ngModelOptions) {
$scope.datepickerOptions.ngModelOptions = ngModelOptions;
}

if (isHtml5DateInput) {
if ($attrs.type === 'month') {
$scope.datepickerOptions.datepickerMode = 'month';
Expand All @@ -2826,20 +2830,20 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
value = new Date(value);
}

$scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone);
$scope.date = value; // Customization: do not convert the model!

return dateParser.filter($scope.date, dateFormat);
return dateParser.filter(dateParser.fromTimezone(value, ngModelOptions.timezone), dateFormat); // Customization: convert only the date displayed
});
} else {
ngModel.$formatters.push(function(value) {
$scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone);
$scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone); // This is probably wrong, a formatter should not convert the model, but I did not try it so I leave it as is
return value;
});
}

// Detect changes in the view from the text box
ngModel.$viewChangeListeners.push(function() {
$scope.date = parseDateString(ngModel.$viewValue);
$scope.date = dateParser.toTimezone(parseDateString(ngModel.$viewValue), ngModelOptions.timezone); // Customization: convert the text input date
});

$element.on('keydown', inputKeydownBind);
Expand Down Expand Up @@ -2914,7 +2918,10 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
// Inner change
$scope.dateSelection = function(dt) {
$scope.date = dt;
var date = $scope.date ? dateParser.filter($scope.date, dateFormat) : null; // Setting to NULL is necessary for form validators to function

// Customization: convert the date to display as in the formatter (a cleaner way would consist in calling the ng-model formatter instead of formatting manually)
var date = $scope.date ? dateParser.filter(dateParser.fromTimezone($scope.date, ngModelOptions.timezone), dateFormat) : null; // Setting to NULL is necessary for form validators to function

$element.val(date);
ngModel.$setViewValue(date);

Expand Down

0 comments on commit 6b50b31

Please sign in to comment.