Skip to content

Fixing o2.Utilities.phpToMoment to support escaping #140

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fixing o2.Utilities.phpToMoment to support escaping #140

wants to merge 2 commits into from

Conversation

mariovalney
Copy link

@mariovalney mariovalney commented May 11, 2017

o2.Utilities.phpToMoment should support escape some chars like in pt_BR and pt_PT dates.

For example, j \d\e F \d\e Y should return D[ ][d][e][ ]MMMM[ ][d][e][ ]YYYY.

Issue #135

@mariovalney
Copy link
Author

Is this still valid?

Some feedback would be appreciated. :)

Copy link
Contributor

@pablinos pablinos left a comment

Choose a reason for hiding this comment

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

I spotted this PR because I was working on something else. I realise it was submitted a while ago, but thanks for taking the time to work on this!

I've added a few comments that I hope are helpful. It would also be really useful to write a few tests to cover these cases.

Thanks again!

@@ -7,6 +7,12 @@ o2.Utilities.phpToMoment = function( s ) {
var m = '';
var lookBehind = '';
for ( var i = 0; i < s.length; i++ ) {
if ( lookBehind === "\\" ) { // Scaping character
Copy link
Contributor

Choose a reason for hiding this comment

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

A nitpick but the comment should be 'Escaping character'

@@ -7,6 +7,12 @@ o2.Utilities.phpToMoment = function( s ) {
var m = '';
var lookBehind = '';
for ( var i = 0; i < s.length; i++ ) {
if ( lookBehind === "\\" ) { // Scaping character
m += '[' + s.charAt( i ) + ']';
lookBehind = s.charAt( i );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to do this? There are checks for sequences like jS, but if the j has been escaped then it may not be appropriate to trigger the substitution. Perhaps lookBehind should be empty?

@@ -106,6 +112,7 @@ o2.Utilities.phpToMoment = function( s ) {
case 'u': // Microseconds
case 'I': // Daylight savings time
case 'Z': // Timezone offset in seconds
case '\\': // Scape character
Copy link
Contributor

Choose a reason for hiding this comment

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

Same nitpick comment as above :)

@@ -106,6 +112,7 @@ o2.Utilities.phpToMoment = function( s ) {
case 'u': // Microseconds
case 'I': // Daylight savings time
case 'Z': // Timezone offset in seconds
case '\\': // Scape character
Copy link
Contributor

Choose a reason for hiding this comment

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

Might there be a case for looking forward at this point and incrementing i? You'd have to be clever with the setting of lookBehind below, but it would keep the conditional logic all in the switch statement.

It's more something to think to check we're taking the right approach, than anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants