Skip to content

Fix: DateTimePicker passes current seconds as the selected seconds value - #15495

Merged
jorgefilipecosta merged 1 commit into
masterfrom
fix/dateTimePicker-passes-current-seconds-as-the-selected-value-for-seconds
Jun 7, 2019
Merged

jorgefilipecosta merged 1 commit into
masterfrom
fix/dateTimePicker-passes-current-seconds-as-the-selected-value-for-seconds

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

Closes: #13898

DateTimePicker does not allow users to pick a value for seconds, so when the user changes a time/date, it should look like a value of 0 was selected as the seconds value. Currently, the seconds of the current date are passed as the selected seconds, which may make it look like a "random" value was selected as the seconds value.

This causes a regression where WP_CRON missed some scheduled posts.

How has this been tested?

I created a new post.
I changed the date/time fields in the post scheduling dialog and I verified with redux dev tools that the editPost action contained a date whose seconds were equal to 0.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Document Settings Document settings experience labels May 8, 2019
@gziolo gziolo added the Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code label May 10, 2019
@gziolo

gziolo commented May 10, 2019

Copy link
Copy Markdown
Member

This PR needs to be rebased with master to make Travis green again :)

@jorgefilipecosta
jorgefilipecosta force-pushed the fix/dateTimePicker-passes-current-seconds-as-the-selected-value-for-seconds branch 2 times, most recently from e2a710f to d1b1f66 Compare May 13, 2019 10:01
@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Hi @gziolo this PR was rebased.

@mapk

mapk commented May 30, 2019

Copy link
Copy Markdown
Contributor

This is great! Thanks for fixing @jorgefilipecosta!

@katsar0v

katsar0v commented Jun 4, 2019

Copy link
Copy Markdown

Any update on this?

@noisysocks

Copy link
Copy Markdown
Member

This causes a regression where WP_CRON missed some scheduled posts.

Could you elaborate on this? What causes cron to miss the posts?

@katsar0v

katsar0v commented Jun 6, 2019 •

Copy link
Copy Markdown

Could you elaborate on this? What causes cron to miss the posts?

I explained it here - #13898 (comment)
But will try again. There are missed schedules (e.g.: https://www.hostinger.com/tutorials/how-to-fix-wordpress-missed-schedule) and there is this famous plugin which fixes it all: https://github.com/sLaNGjI/wp-missed-schedule

Use case: I setup wordpress to use system cron (setup a cronjob calling the wp-cron every minute for example). After setting up the cronjob I plan a post for the next week on 20:00. The time in database stored is 20:00:43 (43 in this case is seconds, fully random, but in fact this are my browser seconds).
Now the cronjob runs every minute and starts on the 0th second. If the cronjob is calling the url via http it might take longer than calling the wp-cron.php via php process (but that's an edge case). When the cron job starts next week on 20:00 the post is not being published, because time is 20:00:01 (time of cron job execution) but the post should be published on 20:00:43 (remember the 43 seconds?).
Now the next time the cron job runs (on 20:01) the post does not get published as well and wordpress says "missed schedule" which really annoys me and probably thousands of other WP users...

@aduth aduth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. A nice refactor of some duplicate logic too 👍

}
}

changeDate( newDate ) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be nice for some docs, even if there's plenty of prior art of no documentation in this component.

@jorgefilipecosta
jorgefilipecosta force-pushed the fix/dateTimePicker-passes-current-seconds-as-the-selected-value-for-seconds branch from d1b1f66 to c270593 Compare June 7, 2019 10:38
@jorgefilipecosta
jorgefilipecosta force-pushed the fix/dateTimePicker-passes-current-seconds-as-the-selected-value-for-seconds branch from c270593 to 62c0af3 Compare June 7, 2019 10:59
@jorgefilipecosta
jorgefilipecosta merged commit 0fff1c5 into master Jun 7, 2019
@youknowriad youknowriad added this to the Gutenberg 5.9 milestone Jun 7, 2019
@youknowriad
youknowriad deleted the fix/dateTimePicker-passes-current-seconds-as-the-selected-value-for-seconds branch May 27, 2020 17:45
manzoorwanijk added a commit that referenced this pull request May 5, 2026
Replaces `startOfMinute( inputToDate(...) )` with a small local helper
that mutates the seconds/ms on the `UTCDateMini` directly.

In `date-fns` v4, `startOfMinute` calls `toDate()`, which goes through
`constructFrom()` and does `new input.constructor(value)`. With our
`UTCDateMini` (extends `Date`) plus `timezone-mock` swapping the global
`Date` in tests, that re-construction trips MockDate's "Unhandled type
passed... object" assertion, breaking 50+ DateTimePicker/TimePicker
tests.

Setting seconds and milliseconds via the UTCDateMini's own setSeconds
keeps the truncation in UTC (UTCDateMini's prototype shim reroutes
setSeconds to setUTCSeconds), preserves the existing #15495 behaviour,
and decouples this code path from `date-fns` — useful for future
upgrades.
manzoorwanijk added a commit that referenced this pull request May 5, 2026
Replaces `startOfMinute( inputToDate(...) )` with a small local helper
that mutates the seconds/ms on the `UTCDateMini` directly.

In `date-fns` v4, `startOfMinute` calls `toDate()`, which goes through
`constructFrom()` and does `new input.constructor(value)`. With our
`UTCDateMini` (extends `Date`) plus `timezone-mock` swapping the global
`Date` in tests, that re-construction trips MockDate's "Unhandled type
passed... object" assertion, breaking 50+ DateTimePicker/TimePicker
tests.

Setting seconds and milliseconds via the UTCDateMini's own setSeconds
keeps the truncation in UTC (UTCDateMini's prototype shim reroutes
setSeconds to setUTCSeconds), preserves the existing #15495 behaviour,
and decouples this code path from `date-fns` — useful for future
upgrades.
manzoorwanijk added a commit that referenced this pull request May 5, 2026
Replaces `startOfMinute( inputToDate(...) )` with a small local helper
that mutates the seconds/ms on the `UTCDateMini` directly.

In `date-fns` v4, `startOfMinute` calls `toDate()`, which goes through
`constructFrom()` and does `new input.constructor(value)`. With our
`UTCDateMini` (extends `Date`) plus `timezone-mock` swapping the global
`Date` in tests, that re-construction trips MockDate's "Unhandled type
passed... object" assertion, breaking 50+ DateTimePicker/TimePicker
tests.

Setting seconds and milliseconds via the UTCDateMini's own setSeconds
keeps the truncation in UTC (UTCDateMini's prototype shim reroutes
setSeconds to setUTCSeconds), preserves the existing #15495 behaviour,
and decouples this code path from `date-fns` — useful for future
upgrades.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Document Settings Document settings experience Good First Review A PR that's suitable for someone looking to contribute for the first time by reviewing code [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing seconds when planning a post

7 participants