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

fix(filter): format timezone correctly #9534

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 8 additions & 3 deletions src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,13 @@ function dateStrGetter(name, shortForm) {
};
}

function timeZoneGetter(date) {
var zone = -1 * date.getTimezoneOffset();
function timeZoneGetter(date, formats, timezone) {
var zone;
if (timezone && timezone === 'UTC') {
zone = 0;
} else {
zone = -1 * date.getTimezoneOffset();
}
var paddedZone = (zone >= 0) ? "+" : "";

paddedZone += padNumber(Math[zone > 0 ? 'floor' : 'ceil'](zone / 60), 2) +
Expand Down Expand Up @@ -471,7 +476,7 @@ function dateFilter($locale) {
}
forEach(parts, function(value){
fn = DATE_FORMATS[value];
text += fn ? fn(date, $locale.DATETIME_FORMATS)
text += fn ? fn(date, $locale.DATETIME_FORMATS, timezone)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems really hackish to me, any suggestions?

: 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 @@ -407,6 +407,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');
});
});
});