revert(dateparser): change template literal to '

This reverts commit 9513f1007f.

Fixes #5091

BREAKING CHANGE: Reverts back to original template literal with `'` instead of `\''
This commit is contained in:
Wesley Cho
2016-01-06 18:47:19 -08:00
parent e1723bf09d
commit f40066af9e
3 changed files with 37 additions and 34 deletions
+6 -6
View File
@@ -179,16 +179,16 @@ angular.module('ui.bootstrap.dateparser', [])
var map = [], regex = format.split('');
// check for literal values
var quoteIndex = format.indexOf('`');
var quoteIndex = format.indexOf('\'');
if (quoteIndex > -1) {
var inLiteral = false;
format = format.split('');
for (var i = quoteIndex; i < format.length; i++) {
if (inLiteral) {
if (format[i] === '`') {
if (i + 1 < format.length && format[i + 1] === '\`') { // escaped backtick
format[i + 1] = '$';
regex[i + 1] = '';
if (format[i] === '\'') {
if (i + 1 < format.length && format[i+1] === '\'') { // escaped single quote
format[i+1] = '$';
regex[i+1] = '';
} else { // end of literal
regex[i] = '';
inLiteral = false;
@@ -196,7 +196,7 @@ angular.module('ui.bootstrap.dateparser', [])
}
format[i] = '$';
} else {
if (format[i] === '`') { // start of literal
if (format[i] === '\'') { // start of literal
format[i] = '$';
regex[i] = '';
inLiteral = true;
+22 -22
View File
@@ -15,7 +15,7 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
* `format`
_(Type: `string`, Example: `yyyy/MMM/d`)_ -
The format we want to use. Check all the supported formats below.
* `baseDate`
_(Type: `Date`, Example: `new Date()`)_ -
If you want to parse a date but maintain the timezone, you can pass an existing date here.
@@ -23,33 +23,33 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
##### return
* If the specified input matches the format, a new date with the input will be returned, otherwise, it will return undefined.
### uibDateParser's format codes
* `yyyy`
_(Example: `2015`)_ -
Parses a 4 digits year.
* `yy`
_(Example: `15`)_ -
Parses a 2 digits year.
* `y`
_(Example: `15`)_ -
Parses a year with 1, 2, 3, or 4 digits.
* `MMMM`
_(Example: `February`, i18n support)_ -
Parses the full name of a month.
* `MMM`
_(Example: `Feb`, i18n support)_ -
Parses the short name of a month.
* `MM`
_(Example: `12`, Leading 0)_ -
Parses a numeric month.
* `M`
_(Example: `3`)_ -
Parses a numeric month.
@@ -61,7 +61,7 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
* `dd`
_(Example: `05`, Leading 0)_ -
Parses a numeric day.
* `d`
_(Example: `5`)_ -
Parses a numeric day.
@@ -69,11 +69,11 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
* `d!`
_(Example: `3` or `03`)_ -
Parses a numeric day, but allowing an optional leading zero
* `EEEE`
_(Example: `Sunday`, i18n support)_ -
Parses the full name of a day.
* `EEE`
_(Example: `Mon`, i18n support)_ -
Parses the short name of a day.
@@ -81,39 +81,39 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
* `HH`
_(Example: `14`, Leading 0)_ -
Parses a 24 hours time.
* `H`
_(Example: `3`)_ -
Parses a 24 hours time.
* `hh`
_(Example: `11`, Leading 0)_ -
Parses a 12 hours time.
* `h`
_(Example: `3`)_ -
Parses a 12 hours time.
* `mm`
_(Example: `09`, Leading 0)_ -
Parses the minutes.
* `m`
_(Example: `3`)_ -
Parses the minutes.
* `sss`
_(Example: `094`, Leading 0)_ -
Parses the milliseconds.
* `ss`
_(Example: `08`, Leading 0)_ -
Parses the seconds.
* `s`
_(Example: `22`)_ -
Parses the seconds.
* `a`
_(Example: `10AM`)_ -
Parses a 12 hours time with AM/PM.
@@ -136,9 +136,9 @@ Certain format codes support i18n. Check this [guide](https://docs.angularjs.org
* `GGGG`
_(Example: `Anno Domini`)_ -
Parses the long form of the era (`Anno Domini` or `Before Christ`)
\* 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.
\** It also supports `fullDate|longDate|medium|mediumDate|mediumTime|short|shortDate|shortTime` as the format for parsing.
\*** 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 `\`\`\`\``.
\*** 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 `''''`.
+9 -6
View File
@@ -310,20 +310,23 @@ describe('date parser', function() {
describe('with value literals', function() {
it('should work with multiple literals', function() {
expect(dateParser.parse('29 de January de 2013', 'd `de` MMMM `de` y')).toEqual(new Date(2013, 0, 29));
expect(dateParser.parse('22.March.15 12 o\'clock', 'd.MMMM.yy h `o\'clock`')).toEqual(new Date(2015, 2, 22, 12));
expect(dateParser.parse('29 de January de 2013', 'd \'de\' MMMM \'de\' y')).toEqual(new Date(2013, 0, 29));
});
it('should work with only a backtick', function() {
expect(dateParser.parse('22.March.15 `', 'd.MMMM.yy `\`\``')).toEqual(new Date(2015, 2, 22));
it('should work with escaped single quote', function() {
expect(dateParser.parse('22.March.15 12 o\'clock', 'd.MMMM.yy h \'o\'\'clock\'')).toEqual(new Date(2015, 2, 22, 12));
});
it('should work with only a single quote', function() {
expect(dateParser.parse('22.March.15 \'', 'd.MMMM.yy \'\'\'')).toEqual(new Date(2015, 2, 22));
});
it('should work with trailing literal', function() {
expect(dateParser.parse('year 2013', '`year` y')).toEqual(new Date(2013, 0, 1));
expect(dateParser.parse('year 2013', '\'year\' y')).toEqual(new Date(2013, 0, 1));
});
it('should work without whitespace', function() {
expect(dateParser.parse('year:2013', '`year:`y')).toEqual(new Date(2013, 0, 1));
expect(dateParser.parse('year:2013', '\'year:\'y')).toEqual(new Date(2013, 0, 1));
});
});