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 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
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, formatProp) {
return function(date, formats) {
var value = date['get' + name]();
var get = uppercase(shortForm ? ('SHORT' + name) : name);
var propName = formatProp || name;
var get = uppercase(shortForm ? ('SHORT' + propName) : propName);
Copy link
Contributor

Choose a reason for hiding this comment

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

If we change this to

function dateStrGetter(name, shortForm, propPrefix) {
...
var get = uppercase((propPrefix || '') + (shortForm ? 'Short' : '') + name);
...

And also change the line below to

LLLL: dateStrGetter('Month', false, 'Standalone'),

Then, in the future, we can implement LLL by just doing

LLL: dateStrGetter('Month', true, 'Standalone'),

[To change Standalone to a boolean is also fine]

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point ! (It was late 😛)
I went with the boolean (but it's easy to switch to a string prefix if needed).


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, 'StandaloneMonth'),
Copy link
Contributor

Choose a reason for hiding this comment

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

StandAlone (as two words)

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to boolean 😃

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 sam = $locale.DATETIME_FORMATS.STANDALONEMONTH;
var _sept = sam[8];
var _saSept = 'standalone-' + _sept;

// Overwrite September in STANDALONEMONTH
sam[8] = _saSept;

expect(date(noon, 'MMMM')).toEqual(_sept);
expect(date(noon, 'LLLL')).toEqual(_saSept);

// Restore September in STANDALONEMONTH
sam[8] = _sept;
}));

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