Page 1 of 1
Proper timezone offset for HTML5 datetime attribute
Posted: Mon Sep 05, 2011 4:48 am
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
Re: Proper timezone offset for HTML5 datetime attribute
Posted: Tue Sep 06, 2011 5:00 am
by LazyBadger
string_format modifier?!
Re: Proper timezone offset for HTML5 datetime attribute
Posted: Tue Sep 06, 2011 8:58 am
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.
Re: Proper timezone offset for HTML5 datetime attribute
Posted: Tue Sep 06, 2011 11:49 am
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
Re: Proper timezone offset for HTML5 datetime attribute
Posted: Tue Sep 06, 2011 12:25 pm
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/
Re: Proper timezone offset for HTML5 datetime attribute
Posted: Tue Sep 06, 2011 1:19 pm
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
Re: Proper timezone offset for HTML5 datetime attribute
Posted: Tue Sep 06, 2011 1:22 pm
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