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

Commit c7e69fd

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 Closes #11266
1 parent 53c4561 commit c7e69fd

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/ng/filter/filters.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ function eraGetter(date, formats) {
306306
return date.getFullYear() <= 0 ? formats.ERAS[0] : formats.ERAS[1];
307307
}
308308

309+
function longEraGetter(date, formats) {
310+
return date.getFullYear() <= 0 ? formats.ERANAMES[0] : formats.ERANAMES[1];
311+
}
312+
309313
var DATE_FORMATS = {
310314
yyyy: dateGetter('FullYear', 4),
311315
yy: dateGetter('FullYear', 2, 0, true),
@@ -333,10 +337,13 @@ var DATE_FORMATS = {
333337
Z: timeZoneGetter,
334338
ww: weekGetter(2),
335339
w: weekGetter(1),
336-
G: eraGetter
340+
G: eraGetter,
341+
GG: eraGetter,
342+
GGG: eraGetter,
343+
GGGG: longEraGetter
337344
};
338345

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

342349
/**
@@ -373,6 +380,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|
373380
* * `'Z'`: 4 digit (+sign) representation of the timezone offset (-1200-+1200)
374381
* * `'ww'`: Week of year, padded (00-53). Week 01 is the week with the first Thursday of the year
375382
* * `'w'`: Week of year (0-53). Week 1 is the week with the first Thursday of the year
383+
* * `'G'`, `'GG'`, `'GGG'`: The abbreviated form of the era string (e.g. 'AD')
384+
* * `'GGGG'`: The long form of the era string (e.g. 'Anno Domini')
376385
*
377386
* `format` string can also be one of the following predefined
378387
* {@link guide/i18n localizable formats}:

test/ng/filter/filtersSpec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ describe('filters', function() {
229229
});
230230
});
231231

232-
ddescribe('date', function() {
232+
describe('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
@@ -301,6 +301,15 @@ describe('filters', function() {
301301

302302
expect(date(noon, "MMMM dd, y G")).
303303
toEqual('September 03, 2010 AD');
304+
305+
expect(date(noon, "MMMM dd, y GG")).
306+
toEqual('September 03, 2010 AD');
307+
308+
expect(date(noon, "MMMM dd, y GGG")).
309+
toEqual('September 03, 2010 AD');
310+
311+
expect(date(noon, "MMMM dd, y GGGG")).
312+
toEqual('September 03, 2010 Anno Domini');
304313
});
305314

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

0 commit comments

Comments
 (0)