Skip to content
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

Wrong usage of mysql2date to generate datePublished and dateModified, bug in time offsets #6316

Closed
DrLightman opened this issue May 26, 2021 · 3 comments · Fixed by #6318
Closed
Assignees
Labels
Bug Something isn't working
Milestone

Comments

@DrLightman
Copy link

DrLightman commented May 26, 2021

As the WordPress's mysql2date() PHP doc says:

$date is expected to be local time in MySQL format ('Y-m-d H:i:s').

Please note "local time", not GMT time.

Whereas the AMP plugin uses the GMT values instead, resulting in wrong values in datePublished and dateModified attributes of schemaorg metadata:

[
	'@type'            => is_page() ? 'WebPage' : 'BlogPosting',
	'mainEntityOfPage' => get_permalink(),
	'headline'         => get_the_title(),
	'datePublished'    => mysql2date( 'c', $queried_object->post_date_gmt, false ),
	'dateModified'     => mysql2date( 'c', $queried_object->post_modified_gmt, false ),
]

The resulting datePublished will be wrongly comprised of a datetime local to GMT combined with a not zero offset.
The solution is to remove the _gmt parts from the properties:

[
	'@type'            => is_page() ? 'WebPage' : 'BlogPosting',
	'mainEntityOfPage' => get_permalink(),
	'headline'         => get_the_title(),
	'datePublished'    => mysql2date( 'c', $queried_object->post_date, false ),
	'dateModified'     => mysql2date( 'c', $queried_object->post_modified, false ),
]
@DrLightman DrLightman added the Bug Something isn't working label May 26, 2021
@pierlon
Copy link
Contributor

pierlon commented May 26, 2021

Note that this bug only occurs in WP 5.3 and above, as mysql2date() now makes use of the wp_timezone() function (introduced in WP 5.3) that returns the site's timezone setting.

@pierlon pierlon self-assigned this May 26, 2021
@pierlon pierlon added this to the v2.1.3 milestone May 26, 2021
@westonruter
Copy link
Member

Related: #5335

@pierlon
Copy link
Contributor

pierlon commented Jul 1, 2021

(QA comment: #6318 (comment))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants