msm-sitemap icon indicating copy to clipboard operation
msm-sitemap copied to clipboard

adding fix to ticket 157 setting the query date to use the timezone o…

Open juankk opened this issue 4 years ago • 3 comments

…f the site

juankk avatar Mar 10 '20 03:03 juankk

Should it not use UTC timestamps for all data saved and queried? WP stores all time and date values as UTC timestamps, then converts into localised time when displayed. The server too should be using UTC time.

Needing to use localised time to query implies that either somebody incorrectly used localised times somewhere and stripped out the timezones so that 2pm Sydney time became 2pm UTC, or that the timestamps are being stored incorrectly by the plugin. by my understanding this PR will break things for some or all users

tomjn avatar Mar 10 '20 14:03 tomjn

Should it not use UTC timestamps for all data saved and queried?

It currently queries post_date which is a localised timestamp. An alternative could be to query post_date_gmt but this column is not indexed.

t-wright avatar Mar 10 '20 23:03 t-wright

@tomjn I work with @juankk and trying to follow up on this to find a resolution. I understand your concern and @t-wright's thought on using post_date_gmt is sort of a good idea except UTC !== GMT for things like DST.

Regardless, perhaps a way forward here, and I can submit a PR with a different approach, is to use filters here. And also maybe hardened libraries for this.

Idea:

$start_date = apply_filters( 'msm_sitemap/start_date', function ( $start_date ) {
	$date = new \DateTime( $time, new \DateTimeZone( 'Australia/Sydney' ) );
	
	return $date->format( 'Y-m-d H:i:s' );
} );

$end_date = apply_filters( 'msm_sitemap/end_date', function ( $end_date ) {
	$date = new \DateTime( $time, new \DateTimeZone( 'Australia/Sydney' ) );
	
	return $date->format( 'Y-m-d H:i:s' );
} );

Thoughts?

technosailor avatar May 07 '20 19:05 technosailor