Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit f40066a

Browse files
committed
revert(dateparser): change template literal to '
This reverts commit 9513f10. Fixes #5091 BREAKING CHANGE: Reverts back to original template literal with `'` instead of `\''
1 parent e1723bf commit f40066a

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

src/dateparser/dateparser.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,24 @@ angular.module('ui.bootstrap.dateparser', [])
179179
var map = [], regex = format.split('');
180180

181181
// check for literal values
182-
var quoteIndex = format.indexOf('`');
182+
var quoteIndex = format.indexOf('\'');
183183
if (quoteIndex > -1) {
184184
var inLiteral = false;
185185
format = format.split('');
186186
for (var i = quoteIndex; i < format.length; i++) {
187187
if (inLiteral) {
188-
if (format[i] === '`') {
189-
if (i + 1 < format.length && format[i + 1] === '\`') { // escaped backtick
190-
format[i + 1] = '$';
191-
regex[i + 1] = '';
188+
if (format[i] === '\'') {
189+
if (i + 1 < format.length && format[i+1] === '\'') { // escaped single quote
190+
format[i+1] = '$';
191+
regex[i+1] = '';
192192
} else { // end of literal
193193
regex[i] = '';
194194
inLiteral = false;
195195
}
196196
}
197197
format[i] = '$';
198198
} else {
199-
if (format[i] === '`') { // start of literal
199+
if (format[i] === '\'') { // start of literal
200200
format[i] = '$';
201201
regex[i] = '';
202202
inLiteral = true;

src/dateparser/docs/README.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,41 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
1515
* `format`
1616
_(Type: `string`, Example: `yyyy/MMM/d`)_ -
1717
The format we want to use. Check all the supported formats below.
18-
18+
1919
* `baseDate`
2020
_(Type: `Date`, Example: `new Date()`)_ -
2121
If you want to parse a date but maintain the timezone, you can pass an existing date here.
2222

2323
##### return
2424

2525
* If the specified input matches the format, a new date with the input will be returned, otherwise, it will return undefined.
26-
26+
2727
### uibDateParser's format codes
2828

2929
* `yyyy`
3030
_(Example: `2015`)_ -
3131
Parses a 4 digits year.
32-
32+
3333
* `yy`
3434
_(Example: `15`)_ -
3535
Parses a 2 digits year.
36-
36+
3737
* `y`
3838
_(Example: `15`)_ -
3939
Parses a year with 1, 2, 3, or 4 digits.
40-
40+
4141
* `MMMM`
4242
_(Example: `February`, i18n support)_ -
4343
Parses the full name of a month.
44-
44+
4545
* `MMM`
4646
_(Example: `Feb`, i18n support)_ -
4747
Parses the short name of a month.
48-
48+
4949
* `MM`
5050
_(Example: `12`, Leading 0)_ -
5151
Parses a numeric month.
52-
52+
5353
* `M`
5454
_(Example: `3`)_ -
5555
Parses a numeric month.
@@ -61,59 +61,59 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
6161
* `dd`
6262
_(Example: `05`, Leading 0)_ -
6363
Parses a numeric day.
64-
64+
6565
* `d`
6666
_(Example: `5`)_ -
6767
Parses a numeric day.
6868

6969
* `d!`
7070
_(Example: `3` or `03`)_ -
7171
Parses a numeric day, but allowing an optional leading zero
72-
72+
7373
* `EEEE`
7474
_(Example: `Sunday`, i18n support)_ -
7575
Parses the full name of a day.
76-
76+
7777
* `EEE`
7878
_(Example: `Mon`, i18n support)_ -
7979
Parses the short name of a day.
8080

8181
* `HH`
8282
_(Example: `14`, Leading 0)_ -
8383
Parses a 24 hours time.
84-
84+
8585
* `H`
8686
_(Example: `3`)_ -
8787
Parses a 24 hours time.
88-
88+
8989
* `hh`
9090
_(Example: `11`, Leading 0)_ -
9191
Parses a 12 hours time.
92-
92+
9393
* `h`
9494
_(Example: `3`)_ -
9595
Parses a 12 hours time.
96-
96+
9797
* `mm`
9898
_(Example: `09`, Leading 0)_ -
9999
Parses the minutes.
100-
100+
101101
* `m`
102102
_(Example: `3`)_ -
103103
Parses the minutes.
104-
104+
105105
* `sss`
106106
_(Example: `094`, Leading 0)_ -
107107
Parses the milliseconds.
108-
108+
109109
* `ss`
110110
_(Example: `08`, Leading 0)_ -
111111
Parses the seconds.
112-
112+
113113
* `s`
114114
_(Example: `22`)_ -
115115
Parses the seconds.
116-
116+
117117
* `a`
118118
_(Example: `10AM`)_ -
119119
Parses a 12 hours time with AM/PM.
@@ -136,9 +136,9 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
136136
* `GGGG`
137137
_(Example: `Anno Domini`)_ -
138138
Parses the long form of the era (`Anno Domini` or `Before Christ`)
139-
139+
140140
\* The ones marked with `Leading 0`, needs a leading 0 for values less than 10. Exception being milliseconds which needs it for values under 100.
141141

142142
\** It also supports `fullDate|longDate|medium|mediumDate|mediumTime|short|shortDate|shortTime` as the format for parsing.
143143

144-
\*** It supports template literals as a string between the backtick `\`` character, i.e. `\`The Date is\` MM/DD/YYYY`. If one wants the literal backtick character, one must use `\`\`\`\``.
144+
\*** It supports template literals as a string between the single quote `'` character, i.e. `\`The Date is\` MM/DD/YYYY`. If one wants the literal single quote character, one must use `''''`.

src/dateparser/test/dateparser.spec.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -310,20 +310,23 @@ describe('date parser', function() {
310310

311311
describe('with value literals', function() {
312312
it('should work with multiple literals', function() {
313-
expect(dateParser.parse('29 de January de 2013', 'd `de` MMMM `de` y')).toEqual(new Date(2013, 0, 29));
314-
expect(dateParser.parse('22.March.15 12 o\'clock', 'd.MMMM.yy h `o\'clock`')).toEqual(new Date(2015, 2, 22, 12));
313+
expect(dateParser.parse('29 de January de 2013', 'd \'de\' MMMM \'de\' y')).toEqual(new Date(2013, 0, 29));
315314
});
316315

317-
it('should work with only a backtick', function() {
318-
expect(dateParser.parse('22.March.15 `', 'd.MMMM.yy `\`\``')).toEqual(new Date(2015, 2, 22));
316+
it('should work with escaped single quote', function() {
317+
expect(dateParser.parse('22.March.15 12 o\'clock', 'd.MMMM.yy h \'o\'\'clock\'')).toEqual(new Date(2015, 2, 22, 12));
318+
});
319+
320+
it('should work with only a single quote', function() {
321+
expect(dateParser.parse('22.March.15 \'', 'd.MMMM.yy \'\'\'')).toEqual(new Date(2015, 2, 22));
319322
});
320323

321324
it('should work with trailing literal', function() {
322-
expect(dateParser.parse('year 2013', '`year` y')).toEqual(new Date(2013, 0, 1));
325+
expect(dateParser.parse('year 2013', '\'year\' y')).toEqual(new Date(2013, 0, 1));
323326
});
324327

325328
it('should work without whitespace', function() {
326-
expect(dateParser.parse('year:2013', '`year:`y')).toEqual(new Date(2013, 0, 1));
329+
expect(dateParser.parse('year:2013', '\'year:\'y')).toEqual(new Date(2013, 0, 1));
327330
});
328331
});
329332

0 commit comments

Comments
 (0)