Skip to content

Commit 7d4ccea

Browse files
Sujeet Pillaimhevery
Sujeet Pillai
authored andcommitted
fix(timezone): correct timezone date filter for 1/2 hour offsets
1 parent 654dd1d commit 7d4ccea

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/ng/filter/filters.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,8 @@ function timeZoneGetter(date) {
214214
var zone = -1 * date.getTimezoneOffset();
215215
var paddedZone = (zone >= 0) ? "+" : "";
216216

217-
paddedZone += padNumber(zone / 60, 2) + padNumber(Math.abs(zone % 60), 2);
217+
paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) +
218+
padNumber(Math.abs(zone % 60), 2);
218219

219220
return paddedZone;
220221
}

test/ng/filter/filtersSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ describe('filters', function() {
227227
var utc = new angular.mock.TzDate( 0, '2010-09-03T12:05:08.000Z');
228228
var eastOfUTC = new angular.mock.TzDate(-5, '2010-09-03T12:05:08.000Z');
229229
var westOfUTC = new angular.mock.TzDate(+5, '2010-09-03T12:05:08.000Z');
230+
var eastOfUTCPartial = new angular.mock.TzDate(-5.5, '2010-09-03T12:05:08.000Z');
231+
var westOfUTCPartial = new angular.mock.TzDate(+5.5, '2010-09-03T12:05:08.000Z');
230232

231233
expect(date(utc, "yyyy-MM-ddTHH:mm:ssZ")).
232234
toEqual('2010-09-03T12:05:08+0000')
@@ -236,6 +238,12 @@ describe('filters', function() {
236238

237239
expect(date(westOfUTC, "yyyy-MM-ddTHH:mm:ssZ")).
238240
toEqual('2010-09-03T07:05:08-0500')
241+
242+
expect(date(eastOfUTCPartial, "yyyy-MM-ddTHH:mm:ssZ")).
243+
toEqual('2010-09-03T17:35:08+0530')
244+
245+
expect(date(westOfUTCPartial, "yyyy-MM-ddTHH:mm:ssZ")).
246+
toEqual('2010-09-03T06:35:08-0530')
239247
});
240248

241249
it('should treat single quoted strings as string literals', function() {

0 commit comments

Comments
 (0)