Make WordPress Core

Opened 11 months ago

Closed 3 months ago

Last modified 3 months ago

#60184 closed defect (bug) (fixed)

Publication date 01/01/1970 is refused

Reported by: emmanuel78's profile emmanuel78 Owned by: kadamwhite's profile kadamwhite
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.4.2
Component: REST API Keywords: has-patch has-unit-tests commit
Focuses: rest-api Cc:

Description

I want to publish an artical refering to a real book.
Then the publication date is set with to book one and not the article publication date.

Defect => the jan-01-1970 is refused by WordPress.
Instead of, I set jan-02-1970

Attachments (1)

01-01-1970-midnight.png (24.5 KB) - added by sabernhardt 3 months ago.
trying to publish at midnight (U.S. Central) January 1, 1970

Download all attachments as: .zip

Change History (11)

@sabernhardt
3 months ago

trying to publish at midnight (U.S. Central) January 1, 1970

#1 @sabernhardt
3 months ago

  • Component changed from General to Editor
  • Focuses rest-api added

Hi and welcome to WordPress Core Trac!

I received a REST API error message when I tried to save a post in the (block) editor with a publish date of 01/01/1970 at midnight local time. If it compares against the Unix epoch time with a less than or greater than operator, that may need to account for equality too (<=).

For workarounds:

  • I was able to set the publish date to 12:01am in the editor.
  • Quick Edit allows setting the time to 00:00.

This ticket was mentioned in PR #7277 on WordPress/wordpress-develop by @siliconforks.


3 months ago
#2

  • Keywords has-patch has-unit-tests added

This fixes handling of dates representing the Unix epoch (1970-01-01T00:00:00Z).

Trac ticket: https://core.trac.wordpress.org/ticket/60184

#3 @siliconforks
3 months ago

  • Keywords needs-testing added

Here is an easy way to reproduce this issue using only the command line:

curl \
  -X POST WORDPRESS_URL/wp-json/wp/v2/posts \
  -u 'USERNAME:APPLICATION_PASSWORD' \
  -H 'Content-Type: application/json; charset=UTF-8' \
  -d '{"title":"Post created via REST API","date_gmt":"1970-01-01T00:00:00Z"}'

Change:

  • WORDPRESS_URL to the URL of your WordPress installation
  • USERNAME to your WordPress admin username (or at least some user with the capability of creating posts)
  • APPLICATION_PASSWORD to an application password for that user

#4 @peterwilsoncc
3 months ago

  • Component changed from Editor to REST API

As the bug is in the REST API's code, I've updated to component to ensure the issue is seen by the correct component maintainers.

#5 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 6.7

This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.


3 months ago

#7 @drjosh07
3 months ago

  • Keywords needs-testing removed

Test Report

Environment

  • Server: Apache (Linux)
  • WordPress: 6.7-alpha-58576-src
  • Browser: Chrome 128.0.6613.138
  • OS: Mac
  • Theme: Twenty Twenty-Four
  • Plugins: None activated

Steps to Reproduce

  1. Create a new post
  2. Set the publish date to be January 1st, 1970 at 12:00 a.m.
  3. Attempt to publish the post.
  4. A red banner will appear stating that "Updating failed. Invalid parameter(s): date"
  5. Confirmed seeing the issue when the error was reported.

Results

  • Issue reproduced. ✅
  • Confirmed post create at January 1st, 1970 at 12:00 a.m. was successful.

Applied PR from GitHub.

#8 @antpb
3 months ago

  • Keywords commit added
  • Owner set to kadamwhite
  • Status changed from new to assigned

Reviewed this patch during contributor day for commit, marking commit! Hi @kadamwhite !

#9 @kadamwhite
3 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 59040:

REST API: Allow posts to be published with a publication date of midnight 1970-01-01.

Explicitly checks date parsing return values for false, so that 0 (the value returned for the UNIX epoch of 1970-01-01 00:00:00) is correctly treated as a valid timestamp.

It should be valid to create a post dated to any point in history.

Props emmanuel78, sabernhardt, siliconforks, drjosh07, antpb, TimothyBlynJacobs.
Fixes #60184.

@kadamwhite commented on PR #7277:


3 months ago
#10

Thanks for your contribution! This has been committed in changeset r59040, Git hash 71c69dad2e05fd51c508b1311805083943dc5398

Note: See TracTickets for help on using tickets.