Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 347a1aa

Browse files
committed
fixup! simplify and improve test info
1 parent 3a985cf commit 347a1aa

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/ng/directive/input.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,10 +1444,11 @@ function createDateInputType(type, regexp, parseDate, format) {
14441444
// Note: We cannot read ctrl.$modelValue, as there might be a different
14451445
// parser/formatter in the processing chain so that the model
14461446
// contains some different data format!
1447-
if (timezone && previousTimezone && previousTimezone !== timezone) {
1448-
// If the timezone has changed, adjust the previousDate to the default timzeone
1447+
1448+
if (previousTimezone && previousTimezone !== timezone) {
1449+
// If the timezone has changed, adjust the previousDate to the default timezone
14491450
// so that the new date is converted with the correct timezone offset
1450-
previousDate = addDateMinutes(previousDate, timezoneToOffset(previousTimezone, 0));
1451+
previousDate = addDateMinutes(previousDate, timezoneToOffset(previousTimezone));
14511452
}
14521453

14531454
var parsedDate = parseDate(value, previousDate);

test/ng/directive/inputSpec.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -949,15 +949,23 @@ describe('input', function() {
949949
it('should be possible to override the timezone', function() {
950950
var inputElm = helper.compileInput('<input type="week" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />');
951951

952-
helper.changeInputValueTo('2013-W03');
953-
expect(+$rootScope.value).toBe(Date.UTC(2013, 0, 17));
952+
// January 19 2013 is a Saturday
953+
$rootScope.$apply(function() {
954+
$rootScope.value = new Date(Date.UTC(2013, 0, 19));
955+
});
956+
957+
expect(inputElm.val()).toBe('2013-W03');
954958

955-
inputElm.controller('ngModel').$overrideModelOptions({timezone: '+5000'});
959+
inputElm.controller('ngModel').$overrideModelOptions({timezone: '+2400'});
956960

961+
// To check that the timezone overwrite works, apply an offset of +24 hours.
962+
// Since January 19 is a Saturday, +24 will turn the formatted Date into January 20 - Sunday -
963+
// which is in calendar week 4 instead of 3.
957964
$rootScope.$apply(function() {
958-
// the 17. with an offset of +5000 moves the date into next week
959-
$rootScope.value = new Date(Date.UTC(2013, 0, 18));
965+
$rootScope.value = new Date(Date.UTC(2013, 0, 19));
960966
});
967+
968+
// Verifying that the displayed week is week 4 confirms that overriding the timezone worked
961969
expect(inputElm.val()).toBe('2013-W04');
962970
});
963971

@@ -1966,30 +1974,35 @@ describe('input', function() {
19661974
dealoc(formElm);
19671975
});
19681976

1969-
it('should not reuse the hour part of a previous date object after changing the timezone', function() {
1977+
it('should not reuse the hours part of a previous date object after changing the timezone', function() {
19701978
var inputElm = helper.compileInput('<input type="date" ng-model="value" ng-model-options="{timezone: \'UTC\'}" />');
19711979

19721980
helper.changeInputValueTo('2000-01-01');
1981+
// The Date parser sets the hours part of the Date to 0 (00:00) (UTC)
19731982
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 0));
1983+
expect($rootScope.value.getHours()).toBe(1);
19741984

19751985
// Change the timezone offset so that the display date is a day earlier
19761986
// This does not change the model, but our implementation
19771987
// internally caches a Date object with this offset
1978-
// and re-uses it if part of the date changes
1988+
// and re-uses it if part of the Date changes.
1989+
// See https://github.com/angular/angular.js/commit/1a1ef62903c8fdf4ceb81277d966a8eff67f0a96
19791990
inputElm.controller('ngModel').$overrideModelOptions({timezone: '-0500'});
19801991
$rootScope.$apply(function() {
19811992
$rootScope.value = new Date(Date.UTC(2000, 0, 1, 0));
19821993
});
19831994
expect(inputElm.val()).toBe('1999-12-31');
19841995

1985-
// Emptying the input should clear the cached date object
1986-
helper.changeInputValueTo('');
1987-
1996+
// At this point, the cached Date has its hours set to to 19 (00:00 - 05:00 = 19:00)
19881997
inputElm.controller('ngModel').$overrideModelOptions({timezone: 'UTC'});
1998+
1999+
// When changing the timezone back to UTC, the hours part of the Date should be set to
2000+
// the default 0 (UTC) and not use the modified value of the cached Date object.
19892001
helper.changeInputValueTo('2000-01-01');
19902002
expect(+$rootScope.value).toBe(Date.UTC(2000, 0, 1, 0));
19912003
});
19922004

2005+
19932006
describe('min', function() {
19942007

19952008
it('should invalidate', function() {

0 commit comments

Comments
 (0)