Skip to content

Commit

Permalink
fix(DateObject): localDateValue() returns the wrong value for some da…
Browse files Browse the repository at this point in the history
…ys if there is a daylight savin

Now it uses the timezoneOffset of the specific day to calculate the localDateValue

Closes #345
  • Loading branch information
dalelotts committed Oct 21, 2016
1 parent 3f393dd commit 9520d51
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/js/datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
}

function DateObject () {
var tempDate = new Date()
var tempDate = new Date(arguments[0].utcDateValue)
var localOffset = tempDate.getTimezoneOffset() * 60000

this.utcDateValue = tempDate.getTime()
Expand Down
9 changes: 6 additions & 3 deletions test/configuration/beforeRender.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('beforeRender', function () {
var $compile
beforeEach(module('ui.bootstrap.datetimepicker'))
beforeEach(inject(function (_$compile_, _$rootScope_) {
moment.tz.guess()
moment.locale('en')
$compile = _$compile_
$rootScope = _$rootScope_
Expand Down Expand Up @@ -72,14 +73,16 @@ describe('beforeRender', function () {
it('in day view $dates parameter contains 42 members', function () {
$rootScope.date = moment('2014-01-01T00:00:00.000').toDate()

var offset = new Date().getTimezoneOffset() * 60000
var offsetDate = new Date()

$rootScope.beforeRender = function (dates) {
expect(dates.length).toBe(42)
expect(dates[0].utcDateValue).toBe(1388275200000)
expect(dates[0].localDateValue()).toBe(1388275200000 + offset)
offsetDate.setTime(dates[0].utcDateValue)
expect(dates[0].localDateValue()).toBe(1388275200000 + (offsetDate.getTimezoneOffset() * 60000))
expect(dates[11].utcDateValue).toBe(1389225600000)
expect(dates[11].localDateValue()).toBe(1389225600000 + offset)
offsetDate.setTime(dates[11].utcDateValue)
expect(dates[11].localDateValue()).toBe(1389225600000 + (offsetDate.getTimezoneOffset() * 60000))
}

spyOn($rootScope, 'beforeRender').and.callThrough()
Expand Down

0 comments on commit 9520d51

Please sign in to comment.