Timezone Offsets in WordPress Themes

There is an odd implementation detail of many themes that has created a parsing problem with timestamps. It is actually a WordPress/PHP issue. The below is an excerpt from _s(Underscores) that appears in a large amount of themes.

$time_string = sprintf( $time_string,
   esc_attr( get_the_date( 'c' ) ),
   get_the_date(),
   esc_attr( get_the_modified_date( 'c' ) ),
   get_the_modified_date()
);

The string in question is used in a generated line of HTML, which usually looks like something below.

<time datetime="2016-06-21T22:48:40+00:00">June 21, 2016</time>

A parser reading the above will read it as 10:48PM UTC/GMT. Assuming it converted that into local time, it would actually be 6:48PM EDT. However, in reality, I posted at 10:48PM Eastern Time. It just omitted the timezone offset, putting in +00:00.

The timezone offset is properly shown if you replace ‘c’ with DATE_W3C or DATE_ATOM. The alternative is to add the date in as GMT.  Without proper timezone offsets, posts will be parsed as being at the wrong time.

Related:

https://core.trac.wordpress.org/ticket/25768

https://core.trac.wordpress.org/ticket/20973

 

 

David Shanske

My day job is in training for an airline. I also develop Indieweb WordPress plugins so that others can take control of their online identity.

Leave a Reply

Your email address will not be published. Required fields are marked *