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

Commit ba38421

Browse files
fix(date filter): display localised era for G format code
This implementation is limited to displaying AD years correctly only, since there is no agreed standard on how to represent dates before 1 AD. Closes #10503
1 parent d3097cb commit ba38421

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/ng/filter/filters.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ function ampmGetter(date, formats) {
302302
return date.getHours() < 12 ? formats.AMPMS[0] : formats.AMPMS[1];
303303
}
304304

305+
function eraGetter(date, formats) {
306+
return date.getFullYear() <= 0 ? formats.ERAS[0] : formats.ERAS[1];
307+
}
308+
305309
var DATE_FORMATS = {
306310
yyyy: dateGetter('FullYear', 4),
307311
yy: dateGetter('FullYear', 2, 0, true),
@@ -328,10 +332,11 @@ var DATE_FORMATS = {
328332
a: ampmGetter,
329333
Z: timeZoneGetter,
330334
ww: weekGetter(2),
331-
w: weekGetter(1)
335+
w: weekGetter(1),
336+
G: eraGetter
332337
};
333338

334-
var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEw']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z|w+))(.*)/,
339+
var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z|w+))(.*)/,
335340
NUMBER_STRING = /^\-?\d+$/;
336341

337342
/**

test/ng/filter/filtersSpec.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe('filters', function() {
229229
});
230230
});
231231

232-
describe('date', function() {
232+
ddescribe('date', function() {
233233

234234
var morning = new angular.mock.TzDate(+5, '2010-09-03T12:05:08.001Z'); //7am
235235
var noon = new angular.mock.TzDate(+5, '2010-09-03T17:05:08.012Z'); //12pm
@@ -298,6 +298,9 @@ describe('filters', function() {
298298

299299
expect(date(earlyDate, "MMMM dd, y")).
300300
toEqual('September 03, 1');
301+
302+
expect(date(noon, "MMMM dd, y G")).
303+
toEqual('September 03, 2010 AD');
301304
});
302305

303306
it('should accept negative numbers as strings', function() {

0 commit comments

Comments
 (0)