Skip to content

Commit 42f2875

Browse files
dennishall1caitp
authored andcommitted
docs(dateFilter): add example of string literals in format string
Also changes the wording to include the word "escaped" and "escape", which may help users find the information they're looking for via searching. (ノ◕ヮ◕)ノ*:・゚✧ Closes angular#8770
1 parent b728030 commit 42f2875

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/ng/filter/filters.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEw']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d
352352
* * `'mediumTime'`: equivalent to `'h:mm:ss a'` for en_US locale (e.g. 12:05:08 pm)
353353
* * `'shortTime'`: equivalent to `'h:mm a'` for en_US locale (e.g. 12:05 pm)
354354
*
355-
* `format` string can contain literal values. These need to be quoted with single quotes (e.g.
356-
* `"h 'in the morning'"`). In order to output single quote, use two single quotes in a sequence
355+
* `format` string can contain literal values. These need to be escaped by surrounding with single quotes (e.g.
356+
* `"h 'in the morning'"`). In order to output a single quote, escape it - i.e., two single quotes in a sequence
357357
* (e.g. `"h 'o''clock'"`).
358358
*
359359
* @param {(Date|number|string)} date Date to format either as Date object, milliseconds (string or
@@ -373,6 +373,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEw']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d
373373
<span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
374374
<span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
375375
<span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
376+
<span ng-non-bindable>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>:
377+
<span>{{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}</span><br>
376378
</file>
377379
<file name="protractor.js" type="protractor">
378380
it('should format date', function() {
@@ -382,6 +384,8 @@ var DATE_FORMATS_SPLIT = /((?:[^yMdHhmsaZEw']+)|(?:'(?:[^']|'')*')|(?:E+|y+|M+|d
382384
toMatch(/2010\-10\-2\d \d{2}:\d{2}:\d{2} (\-|\+)?\d{4}/);
383385
expect(element(by.binding("'1288323623006' | date:'MM/dd/yyyy @ h:mma'")).getText()).
384386
toMatch(/10\/2\d\/2010 @ \d{1,2}:\d{2}(AM|PM)/);
387+
expect(element(by.binding("'1288323623006' | date:\"MM/dd/yyyy 'at' h:mma\"")).getText()).
388+
toMatch(/10\/2\d\/2010 at \d{1,2}:\d{2}(AM|PM)/);
385389
});
386390
</file>
387391
</example>

0 commit comments

Comments
 (0)