Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date: Parse literals, e.g., separators #692

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/date/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ return function( value, numberParser, properties ) {

default:
token.type = "literal";
tokenRe = /./;
tokenRe = new RegExp( regexpEscape( current ) );
}

if ( !tokenRe ) {
Expand Down
4 changes: 2 additions & 2 deletions test/functional/date/parse-date.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ QUnit.test( "should parse time presets", function( assert ) {
date.setSeconds( 7 );
date = startOf( date, "second" );
assertParseDate( assert, "5:35:07 PM", { time: "medium" }, date );
assertParseDate( assert, "٥،٣٥،٠٧ م", { time: "medium" }, date, ar );
assertParseDate( assert, "٥:٣٥:٠٧ م", { time: "medium" }, date, ar );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this assertion is doing and what you changed here and why? That might help understand the bigger picture.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous CLDR (when this test was created), ، was used as time separator. In recent CLDR, it was reverted to use : again. Although, the parser was buggy and didn't actually check for that. It was still passing because whatever character was working there. After the fix, this needed fix.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thanks. Now this change makes a lot more sense.

date = startOf( date, "minute" );
assertParseDate( assert, "5:35 PM", { time: "short" }, date );
assertParseDate( assert, "٥،٣٥ م", { time: "short" }, date, ar );
assertParseDate( assert, "٥:٣٥ م", { time: "short" }, date, ar );
});

QUnit.test( "should parse date presets", function( assert ) {
Expand Down
3 changes: 3 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
require([
"qunit",

// util
"./unit/util/regexp/escape",

// core
"./unit/core",
"./unit/core/locale",
Expand Down
7 changes: 7 additions & 0 deletions test/unit/date/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,11 @@ QUnit.test( "should parse literal (')", function( assert ) {
assertParse( assert, "09 o'clock AM", "hh 'o''clock' a", cldr, date );
});

QUnit.test( "should parse invalid literal as null", function( assert ) {
assertParse( assert, "2-20-2017", "M/d/y", cldr, null );
assertParse( assert, "2a20a2017", "M/d/y", cldr, null );
assertParse( assert, "2/20/2017", "M-d-y", cldr, null );
assertParse( assert, "2/20/2017x5xAM", "M/d/y h a", cldr, null );
});

});
18 changes: 18 additions & 0 deletions test/unit/util/regexp/escape.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
define([
"src/util/regexp/escape",
], function( regexpEscape ) {

QUnit.module( "Util regexp escape" );

QUnit.test( "it shouldn't escape not-reserved characters", function( assert ) {
assert.equal( regexpEscape( "foo" ), "foo" );
});

QUnit.test( "it should escape reserved characters", function( assert ) {
assert.equal(
regexpEscape( ".*+?^=!:${}()|\[\]\/\\" ),
"\\.\\*\\+\\?\\^\\=\\!\\:\\$\\{\\}\\(\\)\\|\\[\\]\\/\\\\"
);
});

});