-
Notifications
You must be signed in to change notification settings - Fork 11
Fix date handling compatibility with Safari #134
Conversation
formattedDate += '-' + ( '00' + String( date.getDate() ) ).substr( -nonYearLength, nonYearLength ); | ||
formattedDate += ' ' + ( '00' + String( date.getHours() ) ).substr( -nonYearLength, nonYearLength ); | ||
formattedDate += ':' + ( '00' + String( date.getMinutes() ) ).substr( -nonYearLength, nonYearLength ); | ||
formattedDate += ':' + ( '00' + String( date.getSeconds() ) ).substr( -nonYearLength, nonYearLength ); |
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.
Being explicit about types just in case.
return parseInt( datePart, 10 ); | ||
} ); | ||
return new Date( dateParts[0], dateParts[1] - 1, dateParts[2], dateParts[3], dateParts[4], dateParts[5] ); // eslint-disable-line no-magic-numbers | ||
}, |
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 wish we could pass an array in the Date
object, but one day we will be able to do it using spread syntax, like this, ( though it works in chrome ) 😀
return new Date(...dateParts);
timestampDifferential; | ||
|
||
var snapshot = this, currentDate, currentTimestamp, timestampDifferential; | ||
currentTimestamp = ( new Date() ).valueOf(); |
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.
Just for my knowledge, thinking why you chose ( new Date() ).valueOf()
over ( new Date() ).getTime();
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.
Good question. I don't have a particular reason. I just usually use it, as has the same output:
You can use this method to help assign a date and time to another Date object. This method is functionally equivalent to the valueOf() method.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTime
I agree that getTime()
would perhaps look more semantic.
I opened the customizer in Safari and I found:
It looks like some logic from Customize Posts was adopted before fixes for its Safari issues were implemented. See:
xwp/wp-customize-posts#293
xwp/wp-customize-posts#304