public function date_w3cdtf($date)
{
static $pcre;
if (!$pcre) {
$year = '([0-9]{4})';
$month = $day = $hour = $minute = $second = '([0-9]{2})';
$decimal = '([0-9]*)';
$zone = '(?:(Z)|([+\\-])([0-9]{1,2}):?([0-9]{1,2}))';
$pcre = '/^' . $year . '(?:-?' . $month . '(?:-?' . $day . '(?:[Tt\\x09\\x20]+' . $hour . '(?::?' . $minute . '(?::?' . $second . '(?:.' . $decimal . ')?)?)?' . $zone . ')?)?)?$/';
}
if (preg_match($pcre, $date, $match)) {
/*
Capturing subpatterns:
1: Year
2: Month
3: Day
4: Hour
5: Minute
6: Second
7: Decimal fraction of a second
8: Zulu
9: Timezone ±
10: Timezone hours
11: Timezone minutes
*/
// Fill in empty matches
for ($i = count($match); $i <= 3; $i++) {
$match[$i] = '1';
}
for ($i = count($match); $i <= 7; $i++) {
$match[$i] = '0';
}
// Numeric timezone
if (isset($match[9]) && $match[9] !== '') {
$timezone = $match[10] * 3600;
$timezone += $match[11] * 60;
if ($match[9] === '-') {
$timezone = 0 - $timezone;
}
} else {
$timezone = 0;
}
// Convert the number of seconds to an integer, taking decimals into account
$second = round((int) $match[6] + (int) $match[7] / pow(10, strlen($match[7])));
return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
} else {
return false;
}
}