Skip to content

Commit

Permalink
Use modelOptions.timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
Gillardo committed Jan 23, 2017
1 parent 3ecc7e2 commit 7fc8bff
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-ui-datetime-picker",
"version": "2.5.3",
"version": "2.5.4",
"homepage": "https://github.com/Gillardo/bootstrap-ui-datetime-picker",
"authors": [
"Gillardo <[email protected]>"
Expand Down
21 changes: 8 additions & 13 deletions datetime-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
closeOnTimeNow: true,
appendToBody: false,
altInputFormats: [],
ngModelOptions: {},
ngModelOptions: { timezone: null },
saveAs: false,
readAs: false
})
Expand Down Expand Up @@ -113,7 +113,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
}

// popup element used to display calendar
var timezone = null;
var popupEl = angular.element('' +
'<div date-picker-wrap>' +
'<div uib-datepicker></div>' +
Expand All @@ -122,21 +121,17 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
'<div uib-timepicker style="margin:0 auto"></div>' +
'</div>');

if (ngModelOptions) {
timezone = ngModelOptions.timezone;
$scope.ngModelOptions = angular.copy(ngModelOptions);
$scope.ngModelOptions.timezone = null;
if ($scope.ngModelOptions.updateOnDefault === true) {
$scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ?
$scope.ngModelOptions.updateOn + ' default' : 'default';
}
$scope.ngModelOptions = angular.copy(ngModelOptions);

popupEl.attr('ng-model-options', 'ngModelOptions');
if ($scope.ngModelOptions.updateOnDefault === true) {
$scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ?
$scope.ngModelOptions.updateOn + ' default' : 'default';
}

// get attributes from directive
popupEl.attr({
'ng-model': 'date',
'ng-model-options': 'ngModelOptions',
'ng-change': 'dateSelection(date)'
});

Expand Down Expand Up @@ -414,14 +409,14 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo

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

var dates = {};
angular.forEach(['minDate', 'maxDate'], function (key) {
if (!$scope.datepickerOptions[key]) {
dates[key] = null;
} else if (angular.isDate($scope.datepickerOptions[key])) {
dates[key] = uibDateParser.fromTimezone(new Date($scope.datepickerOptions[key]), timezone);
dates[key] = uibDateParser.fromTimezone(new Date($scope.datepickerOptions[key]), ngModelOptions.timezone);
} else {
dates[key] = new Date(dateFilter($scope.datepickerOptions[key], 'medium'));
}
Expand Down
25 changes: 10 additions & 15 deletions dist/datetime-picker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/Gillardo/bootstrap-ui-datetime-picker
// Version: 2.5.3
// Released: 2017-01-20
// Version: 2.5.4
// Released: 2017-01-23
angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bootstrap.position'])
.constant('uiDatetimePickerConfig', {
dateFormat: 'yyyy-MM-dd HH:mm',
Expand Down Expand Up @@ -51,7 +51,7 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
closeOnTimeNow: true,
appendToBody: false,
altInputFormats: [],
ngModelOptions: {},
ngModelOptions: { timezone: null },
saveAs: false,
readAs: false
})
Expand Down Expand Up @@ -116,7 +116,6 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
}

// popup element used to display calendar
var timezone = null;
var popupEl = angular.element('' +
'<div date-picker-wrap>' +
'<div uib-datepicker></div>' +
Expand All @@ -125,21 +124,17 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo
'<div uib-timepicker style="margin:0 auto"></div>' +
'</div>');

if (ngModelOptions) {
timezone = ngModelOptions.timezone;
$scope.ngModelOptions = angular.copy(ngModelOptions);
$scope.ngModelOptions.timezone = null;
if ($scope.ngModelOptions.updateOnDefault === true) {
$scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ?
$scope.ngModelOptions.updateOn + ' default' : 'default';
}
$scope.ngModelOptions = angular.copy(ngModelOptions);

popupEl.attr('ng-model-options', 'ngModelOptions');
if ($scope.ngModelOptions.updateOnDefault === true) {
$scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ?
$scope.ngModelOptions.updateOn + ' default' : 'default';
}

// get attributes from directive
popupEl.attr({
'ng-model': 'date',
'ng-model-options': 'ngModelOptions',
'ng-change': 'dateSelection(date)'
});

Expand Down Expand Up @@ -417,14 +412,14 @@ angular.module('ui.bootstrap.datetimepicker', ['ui.bootstrap.dateparser', 'ui.bo

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

var dates = {};
angular.forEach(['minDate', 'maxDate'], function (key) {
if (!$scope.datepickerOptions[key]) {
dates[key] = null;
} else if (angular.isDate($scope.datepickerOptions[key])) {
dates[key] = uibDateParser.fromTimezone(new Date($scope.datepickerOptions[key]), timezone);
dates[key] = uibDateParser.fromTimezone(new Date($scope.datepickerOptions[key]), ngModelOptions.timezone);
} else {
dates[key] = new Date(dateFilter($scope.datepickerOptions[key], 'medium'));
}
Expand Down
6 changes: 3 additions & 3 deletions dist/datetime-picker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bootstrap-ui-datetime-picker",
"version": "2.5.3",
"version": "2.5.4",
"url": "https://github.com/Gillardo/bootstrap-ui-datetime-picker",
"authors": [
"Gillardo <[email protected]>"
Expand Down

0 comments on commit 7fc8bff

Please sign in to comment.