Skip to content

Commit 7448825

Browse files
committed
fix(setTime): Changed the way the selected date was converted from UTC to local time.
This change fixed the identified issue with New Zeland daylight savings time, and does not appear to introduce any defects. However, there are no tests in place to make sure this works in all cases and all time zones. Fix dalelotts#219
1 parent f6df9ea commit 7448825

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

src/js/datetimepicker.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@
9696
/* istanbul ignore next */
9797
if (configuration.dropdownSelector !== null && ((typeof jQuery === 'undefined') || (typeof jQuery().dropdown !== 'function'))) {
9898
$log.error('Please DO NOT specify the dropdownSelector option unless you are using jQuery AND Bootstrap.js. ' +
99-
'Please include jQuery AND Bootstrap.js, or write code to close the dropdown in the on-set-time callback. \n\n' +
100-
'The dropdownSelector configuration option is being removed because it will not function properly.');
99+
'Please include jQuery AND Bootstrap.js, or write code to close the dropdown in the on-set-time callback. \n\n' +
100+
'The dropdownSelector configuration option is being removed because it will not function properly.');
101101
delete configuration.dropdownSelector;
102102
}
103103
};
@@ -348,7 +348,7 @@
348348

349349
setTime: function setTime(unixDate) {
350350
var tempDate = new Date(unixDate);
351-
var newDate = new Date(tempDate.getTime() + (tempDate.getTimezoneOffset() * 60000));
351+
var newDate = new Date(tempDate.getUTCFullYear(), tempDate.getUTCMonth(), tempDate.getUTCDate(), tempDate.getUTCHours(), tempDate.getUTCMinutes(), tempDate.getUTCSeconds(), tempDate.getUTCMilliseconds());
352352

353353
var oldDate = ngModelController.$modelValue;
354354
ngModelController.$setViewValue(newDate);

test/configuration/renderOn.spec.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*globals describe, beforeEach, it, expect, module, inject */
2+
3+
/**
4+
* @license angular-bootstrap-datetimepicker
5+
* Copyright 2013 Knight Rider Consulting, Inc. http://www.knightrider.com
6+
* License: MIT
7+
*/
8+
9+
/**
10+
*
11+
* @author Dale "Ducky" Lotts
12+
* @since 7/21/13
13+
*/
14+
15+
describe('refreshEvent', function () {
16+
'use strict';
17+
var $rootScope;
18+
var $compile;
19+
beforeEach(module('ui.bootstrap.datetimepicker'));
20+
beforeEach(inject(function (_$compile_, _$rootScope_) {
21+
$compile = _$compile_;
22+
$rootScope = _$rootScope_;
23+
$rootScope.date = null;
24+
}));
25+
26+
describe('throws exception', function () {
27+
it('if value is an empty string', function () {
28+
function compile() {
29+
$compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ renderOn: \'\' }"></datetimepicker>')($rootScope);
30+
}
31+
32+
expect(compile).toThrow('invalid renderOn value: ');
33+
});
34+
it('if value is a numeric value', function () {
35+
function compile() {
36+
$compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ minView: 0 }"></datetimepicker>')($rootScope);
37+
}
38+
39+
expect(compile).toThrow('invalid minView value: 0');
40+
});
41+
it('if value is greater than startView', function () {
42+
function compile() {
43+
$compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ startView: \'month\', minView: \'year\' }"></datetimepicker>')($rootScope);
44+
}
45+
46+
expect(compile).toThrow('startView must be greater than minView');
47+
});
48+
});
49+
describe('does NOT throw exception for valid values', function () {
50+
it('if value is between 1 and 59', function () {
51+
var validViews = ['year', 'month', 'day', 'hour', 'minute'];
52+
53+
for (var i = 0; i < validViews.length; i += 1) {
54+
$compile('<datetimepicker data-ng-model="date" data-datetimepicker-config="{ startView: \'year\', minView: \'' + validViews[i] + '\' }"></datetimepicker>')($rootScope);
55+
}
56+
});
57+
});
58+
});
59+

0 commit comments

Comments
 (0)