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

feat(dateFilter): add support for STANDALONEMONTH in format (LLLL) #14013

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
9 changes: 6 additions & 3 deletions src/ng/filter/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,11 @@ function dateGetter(name, size, offset, trim) {
};
}

function dateStrGetter(name, shortForm) {
function dateStrGetter(name, shortForm, standAlone) {
return function(date, formats) {
var value = date['get' + name]();
var get = uppercase(shortForm ? ('SHORT' + name) : name);
var propPrefix = (standAlone ? 'STANDALONE' : '') + (shortForm ? 'SHORT' : '');
var get = uppercase(propPrefix + name);

return formats[get][value];
};
Expand Down Expand Up @@ -423,6 +424,7 @@ var DATE_FORMATS = {
MMM: dateStrGetter('Month', true),
MM: dateGetter('Month', 2, 1),
M: dateGetter('Month', 1, 1),
LLLL: dateStrGetter('Month', false, true),
dd: dateGetter('Date', 2),
d: dateGetter('Date', 1),
HH: dateGetter('Hours', 2),
Expand All @@ -448,7 +450,7 @@ var DATE_FORMATS = {
GGGG: longEraGetter
};

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

/**
Expand All @@ -468,6 +470,7 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEwG']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|
* * `'MMM'`: Month in year (Jan-Dec)
* * `'MM'`: Month in year, padded (01-12)
* * `'M'`: Month in year (1-12)
* * `'LLLL'`: Stand-alone month in year (January-December)
* * `'dd'`: Day in month, padded (01-31)
* * `'d'`: Day in month (1-31)
* * `'EEEE'`: Day in Week,(Sunday-Saturday)
Expand Down
15 changes: 15 additions & 0 deletions test/ng/filter/filtersSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@ describe('filters', function() {
toEqual('September 03, 2010 Anno Domini');
});

it('should support STANDALONEMONTH in format (`LLLL`)', inject(function($locale) {
var standAloneMonth = $locale.DATETIME_FORMATS.STANDALONEMONTH;
var september = standAloneMonth[8];
var standAloneSeptember = 'StandAlone' + september;

// Overwrite September in STANDALONEMONTH
standAloneMonth[8] = standAloneSeptember;

expect(date(noon, 'MMMM')).toEqual(september);
expect(date(noon, 'LLLL')).toEqual(standAloneSeptember);

// Restore September in STANDALONEMONTH
standAloneMonth[8] = september;
}));

it('should accept negative numbers as strings', function() {
//Note: this tests a timestamp set for 3 days before the unix epoch.
//The behavior of `date` depends on your timezone, which is why we check just
Expand Down