You're asking two completely unrelated questions here. To rephrase:
How can I provide Google with dates in a format that Google's scraper will recognize, as specified in Rich snippets - Reviews?
How can I accumulate time periods and present the result in a format suitable for humans?
Asking two unrelated question in one question is depreciated on SE, and will usually get your question closed, but I am going to answer them anyway.
First question: The ISO 8601 format requested by Google is YYYY-MM-DD
with leading zeros if required, so July the 4th 2013 would be 2013-07-04
.
To format the ISO date you can use the PHP function date
like this:
$isodate = date('Y-m-d', $timestamp);
where $timestamp
is an integer with the number of seconds that has elapsed since the Unix Epoch (January 1 1970 00:00:00 GMT).
Further, Google expects the $isodate
string to be embedded in the page attached to the dtreviewed
property using the syntax one of three metadata schemes (microdata, microformats, or RFDa). You do this in Drupal by overriding the template of page, node, etc. you want to embed the dtreviewed
property in.
Second question: To accumulate time periods, you need to convert periods input by users (such as "1 hour and 5 minutes" or "01:05") to an integer format with seconds resolution. To convert to seconds you multiply the days with 86400, the hours with 3600 and the minutes with 60, so "1 hour and 5 minutes" becomes:
1 (hour) * 3600 + 5 (minutes) * 60 + 0 (seconds) = 3900 (seconds)
and "2 hours and 25 minutes" becomes:
2 (hour) * 3600 + 25 (minutes) * 60 + 0 (seconds) = 8700 (seconds)
To accumulate, you just add the seconds:
3900 + 8700 = 12600 (seconds)
To display in a suitable format, you can use format_interval
.
$interval = 3900 + 8700;
$intervalstring = format_interval($interval, 2);
and $intervalstring
will now be:
3 hours 30 minutes
(You will lose the "and" by using this standard function, if this "and" is important, you'll need to write your own.)
For avoidance of misunderstanding: Goggle is not interested in your time period data. A time period is typically an interval made up of hours and minutes, and not attached to a particular date. Google wants dates (as in year, month and day of month). Dates and time periods are different things, and there is no way you can format a time period as a date, or vice versa.