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

Commit

Permalink
revert(dateparser): change template literal to '
Browse files Browse the repository at this point in the history
This reverts commit 9513f10.

Fixes #5091

BREAKING CHANGE: Reverts back to original template literal with `'` instead of `\''
  • Loading branch information
wesleycho committed Jan 7, 2016
1 parent e1723bf commit f40066a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/dateparser/dateparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,24 @@ 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;
}
}
format[i] = '$';
} else {
if (format[i] === '`') { // start of literal
if (format[i] === '\'') { // start of literal
format[i] = '$';
regex[i] = '';
inLiteral = true;
Expand Down
44 changes: 22 additions & 22 deletions src/dateparser/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,41 @@ 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.

##### 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.
Expand All @@ -61,59 +61,59 @@ 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.

* `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.

* `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.
Expand All @@ -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 `''''`.
15 changes: 9 additions & 6 deletions src/dateparser/test/dateparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});

Expand Down

0 comments on commit f40066a

Please sign in to comment.