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

Commit 3e5b25b

Browse files
committed
feat(dateFilter): add support for STANDALONEMONTH in format (LLLL)
Fixes #13999 Closes #14013
1 parent 0728cc2 commit 3e5b25b

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/ng/filter/filters.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,11 @@ function dateGetter(name, size, offset, trim) {
358358
};
359359
}
360360

361-
function dateStrGetter(name, shortForm) {
361+
function dateStrGetter(name, shortForm, standAlone) {
362362
return function(date, formats) {
363363
var value = date['get' + name]();
364-
var get = uppercase(shortForm ? ('SHORT' + name) : name);
364+
var propPrefix = (standAlone ? 'STANDALONE' : '') + (shortForm ? 'SHORT' : '');
365+
var get = uppercase(propPrefix + name);
365366

366367
return formats[get][value];
367368
};
@@ -423,6 +424,7 @@ var DATE_FORMATS = {
423424
MMM: dateStrGetter('Month', true),
424425
MM: dateGetter('Month', 2, 1),
425426
M: dateGetter('Month', 1, 1),
427+
LLLL: dateStrGetter('Month', false, true),
426428
dd: dateGetter('Date', 2),
427429
d: dateGetter('Date', 1),
428430
HH: dateGetter('Hours', 2),
@@ -448,7 +450,7 @@ var DATE_FORMATS = {
448450
GGGG: longEraGetter
449451
};
450452

451-
var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/,
453+
var DATE_FORMATS_SPLIT = /((?:[^yMLdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|L+|d+|H+|h+|m+|s+|a|Z|G+|w+))(.*)/,
452454
NUMBER_STRING = /^\-?\d+$/;
453455

454456
/**
@@ -468,6 +470,7 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|
468470
* * `'MMM'`: Month in year (Jan-Dec)
469471
* * `'MM'`: Month in year, padded (01-12)
470472
* * `'M'`: Month in year (1-12)
473+
* * `'LLLL'`: Stand-alone month in year (January-December)
471474
* * `'dd'`: Day in month, padded (01-31)
472475
* * `'d'`: Day in month (1-31)
473476
* * `'EEEE'`: Day in Week,(Sunday-Saturday)

test/ng/filter/filtersSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,21 @@ describe('filters', function() {
349349
toEqual('September 03, 2010 Anno Domini');
350350
});
351351

352+
it('should support STANDALONEMONTH in format (`LLLL`)', inject(function($locale) {
353+
var standAloneMonth = $locale.DATETIME_FORMATS.STANDALONEMONTH;
354+
var september = standAloneMonth[8];
355+
var standAloneSeptember = 'StandAlone' + september;
356+
357+
// Overwrite September in STANDALONEMONTH
358+
standAloneMonth[8] = standAloneSeptember;
359+
360+
expect(date(noon, 'MMMM')).toEqual(september);
361+
expect(date(noon, 'LLLL')).toEqual(standAloneSeptember);
362+
363+
// Restore September in STANDALONEMONTH
364+
standAloneMonth[8] = september;
365+
}));
366+
352367
it('should accept negative numbers as strings', function() {
353368
//Note: this tests a timestamp set for 3 days before the unix epoch.
354369
//The behavior of `date` depends on your timezone, which is why we check just

0 commit comments

Comments
 (0)