diff --git a/src/js/datetimepicker.js b/src/js/datetimepicker.js index b1a6aa70..7cdd96f6 100644 --- a/src/js/datetimepicker.js +++ b/src/js/datetimepicker.js @@ -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() diff --git a/test/configuration/beforeRender.spec.js b/test/configuration/beforeRender.spec.js index e5e56b2c..09a1f794 100644 --- a/test/configuration/beforeRender.spec.js +++ b/test/configuration/beforeRender.spec.js @@ -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_ @@ -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()