Proper timezone offset for HTML5 datetime attribute

Skinning and designing Serendipity (CSS, HTML, Smarty)
Post Reply
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Proper timezone offset for HTML5 datetime attribute

Post by yellowled »

HTML5's time element can have a datetime attribute. This requires a proper format to be a valid attribute.

Code: Select all

<time datetime="2011-09-05T04:38:00+02:00">
Now, I can almost do this using @formatTime in Smarty, but unfortunately, strftime's %z would give me +0200 here, not +02:00.

How do I get it to emit the proper format?

YL
LazyBadger
Regular
Posts: 176
Joined: Mon Aug 25, 2008 12:25 pm
Location: Russia
Contact:

Re: Proper timezone offset for HTML5 datetime attribute

Post by LazyBadger »

string_format modifier?!
Quis custodiet ipsos custodes?
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper timezone offset for HTML5 datetime attribute

Post by Timbalu »

yellowled wrote:strftime's %z would give me +0200 here, not +02:00.
This depends on your setlocale setting onto serving server, as far as I know.

In PHP you could use echo date("c"); instead, which is 2011-09-06T08:41:57+02:00
http://php.net/manual/de/function.date.php
or use in addition one of those with the date funktion:
O Difference to Greenwich time (GMT) in hours Example: +0200
P Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3) Example: +02:00

But however, you have do write your own smarty modifier a la ( {$timestamp|mymod_date:"c"} ) or modify the smarty modifier.date_format.php to serve your needs.
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Proper timezone offset for HTML5 datetime attribute

Post by garvinhicking »

Hi!

I'd wait for HTML5 to adapt the proper timezone format before making that move. :-)

They should surely notice that introducing a custom format instead of a standardized existing one isn't sane.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Timbalu
Regular
Posts: 4598
Joined: Sun May 02, 2004 3:04 pm

Re: Proper timezone offset for HTML5 datetime attribute

Post by Timbalu »

Garvin, do you really think they will ever change that once it is out...?

We could workaround it using 'Z' by referencing the timezone value to UTC/GMT
<time datetime="2011-09-05T04:38:00Z"> (no +02:00)

But this isn't save enough if our timestamp is not UTC/GMT and there is summertime and we do not have a correct offset for our local timezone, if I interpret this site correctly, see
http://stevest.com/2011/marking-html5-time-with-php/
Regards,
Ian

Serendipity Styx Edition and additional_plugins @ https://ophian.github.io/ @ https://github.com/ophian
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Proper timezone offset for HTML5 datetime attribute

Post by garvinhicking »

Hi!
Timbalu wrote:Garvin, do you really think they will ever change that once it is out...?
Of course not once it's out. But current HTML5 is just a working draft, many things are subject to change. *THIS* is a subject that should really be up to change.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
yellowled
Regular
Posts: 7111
Joined: Fri Jan 13, 2006 11:46 am
Location: Eutin, Germany
Contact:

Re: Proper timezone offset for HTML5 datetime attribute

Post by yellowled »

garvinhicking wrote:But current HTML5 is just a working draft, many things are subject to change. *THIS* is a subject that should really be up to change.
It is definitely still changing. When I started my new blog, datetime="2011-09-05T13:13:00" was still valid – now it needs the timezone offset. I'll see what I can do using modifiers.

YL
Post Reply