-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Chrome: Adding the post date picker to schedule posts #841
Conversation
This seems good to me, and I'm okay with having to do a little CSS'ing to get it up to snuff ;) However we will encounter some internationalization things. This could already be adressed and I haven't checked so forgive me if I'm wrong. But I immediately notice the AM/PM toggle, which as a european I find mostly useless. So I'm just checking to make sure, have we a plan for hooking into the standards that WordPress' options table gives us here, including date format? Also, can we ease the workload by using some of the code from Calypso? There's no reason to reinvent the wheel since they are both GPL. |
We should pay some mind to this ticket: https://core.trac.wordpress.org/ticket/39222 Specifically on the proposed abstraction that doesn't tie us to Moment specifically. Dunno how we'd want to interop with that patch though. |
If we want to move forward with this branch, maybe we should copy this patch temporarily? |
I'd be fine with that, but the specifics of copying are a bit fuzzy to me. |
Thoughts on these updates? |
I like it! Can we pre-fill the time with the current time, so it isn't empty until you click a date? |
@aduth do you have an idea how to fix this unit test failure? |
088fd8f should clear it up. I don't think we'd intended to allow importing |
088fd8f
to
b394b86
Compare
I'd use some technical 👀 on this. Thanks :) |
.wp-core-ui .editor-post-schedule__clock-am-button.is-toggled, | ||
.wp-core-ui .editor-post-schedule__clock-pm-button.is-toggled { | ||
background: $light-gray-300; | ||
border-color: $dark-gray-100; |
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.
Mixed spacing (needs tab).
const handleChange = ( newDate ) => { | ||
onUpdateDate( newDate.format( 'YYYY-MM-DDTHH:mm:ss' ) ); | ||
}; | ||
const is12HourTime = settings.formats.time.indexOf( 'a' ) !== -1 || settings.formats.time.indexOf( 'A' ) !== -1; |
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.
Can be inaccurate because it's possible to escape characters in the format. In other words, 'H:i:s \a\w\e\s\o\m\e'
is not twelve hour time, but this logic would treat it as though it were.
Also, it could be simpler to force to lower/upper and test index of the one instance of 'a'/'A'.
Accounting for escaping could be tricky, particularly since JavaScript doesn't support lookbehind regular expression patterns. Dunno if there's a better way, but "flipping" the string and doing a look ahead is one option:
/a(?!\\)/i.test( 'h:i:s a'.split( '' ).reverse().join( '' ) )
// true
/a(?!\\)/i.test( 'h:i:s A'.split( '' ).reverse().join( '' ) )
// true
/a(?!\\)/i.test( 'H:i:s \\a\\w\\e\\s\\o\\m\\e'.split( '' ).reverse().join( '' ) )
// false
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.
Even this solution is not perfect because this \\\\\a
is a 12 hour time but the test returns false
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 guess this is the right test /a(?!\\)/i.test( '\\\\\\\\a'.replace(/\\\\/g).split( '' ).reverse().join( '' ) )
995bb12
to
b7e0954
Compare
Rebased this PR. I'm planning to merge this tomorrow if no more raised concerns. |
// To know if the current timezone is a 12 hour time with look for "a" in the time format | ||
// We also make sure this a is not escaped by a "/" | ||
const is12HourTime = /a(?!\\)/i.test( | ||
settings.formats.time | ||
.toLowerCase() // Test only the lower case a | ||
.replace( /\\\\/g, '' ) // Replace "//" with empty strings | ||
.split( '' ).reverse().join( '' ) // Reverse the string and test for "a" not followed by a slash | ||
); |
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 know how old this PR is :), but today we have multiple occurrences of this snippet in the codebase, so it's worth asking:
- Why reverse the string and not use a non-capturing group like
/(?:[^\\])a/
? - If the RegExp already has the
i
flag, why pipe through.toLowerCase
?
This PR adds the post data picker to schedule a post.
react-datepicker
. Are we ok with that? should we create our own date pickermoment
post
date GMT field to ease working with the dates. I know there are some discussions around this in Core. Any information I should know about here?Not done yet
react-datepicker
. This needs to be tweaked (@joen make me pretty 😄)locale
to the moment object globallymoment.locale( locale )
(cc @aduth). Should we do this in thei18n
module assumingmoment
is used globally in WordPress?AM/PM
selector.