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

Commit 9513f10

Browse files
committed
feat(dateparser): change template literal from ' to `
- Changes from ' to ` for template literals - Adds documentation about template literals BREAKING CHANGE: This changes template literals from the single quote `'` to the backtick character `` ` `` for more natural usage with certain strings such as `o'clock`. Closes #4880 Closes #4936 Closes #4938
1 parent d265113 commit 9513f10

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
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 single quote
190-
format[i+1] = '$';
191-
regex[i+1] = '';
188+
if (format[i] === '`') {
189+
if (i + 1 < format.length && format[i + 1] === '\`') { // escaped backtick
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

+2
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,5 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
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.
143+
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 `\`\`\`\``.

src/dateparser/test/dateparser.spec.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,20 @@ 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));
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));
314315
});
315316

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));
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));
322319
});
323320

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

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

0 commit comments

Comments
 (0)