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

fix(filter): format timezone correctly #10857

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ function dateStrGetter(name, shortForm) {
};
}

function timeZoneGetter(date) {
var zone = -1 * date.getTimezoneOffset();
function timeZoneGetter(date, formats, offset) {
var zone = -1 * offset;
var paddedZone = (zone >= 0) ? "+" : "";

paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) +
Expand Down Expand Up @@ -482,13 +482,15 @@ function dateFilter($locale) {
}
}

var dateTimezoneOffset = date.getTimezoneOffset();
if (timezone && timezone === 'UTC') {
date = new Date(date.getTime());
date.setMinutes(date.getMinutes() + date.getTimezoneOffset());
dateTimezoneOffset = 0;
}
forEach(parts, function(value) {
fn = DATE_FORMATS[value];
text += fn ? fn(date, $locale.DATETIME_FORMATS)
text += fn ? fn(date, $locale.DATETIME_FORMATS, dateTimezoneOffset)
: value.replace(/(^'|'$)/g, '').replace(/''/g, "'");
});

Expand Down
1 change: 1 addition & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ describe('filters', function() {
it('should use UTC if the timezone is set to "UTC"', function() {
expect(date(new Date(2003, 8, 10, 3, 2, 4), 'yyyy-MM-dd HH-mm-ss')).toEqual('2003-09-10 03-02-04');
expect(date(new Date(Date.UTC(2003, 8, 10, 3, 2, 4)), 'yyyy-MM-dd HH-mm-ss', 'UTC')).toEqual('2003-09-10 03-02-04');
expect(date(new Date(Date.UTC(2003, 8, 10, 3, 2, 4)), 'yyyy-MM-dd HH-mm-ssZ', 'UTC')).toEqual('2003-09-10 03-02-04+0000');
});
});
});