-
Notifications
You must be signed in to change notification settings - Fork 56
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
base: master
Are you sure you want to change the base?
Conversation
Is this still valid? Some feedback would be appreciated. :) |
There was a problem hiding this 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!
js/utils/timestamp.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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'
js/utils/timestamp.js
Outdated
@@ -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 ); |
There was a problem hiding this comment.
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?
js/utils/timestamp.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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 :)
js/utils/timestamp.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
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 returnD[ ][d][e][ ]MMMM[ ][d][e][ ]YYYY
.Issue #135