recover from datetime parse issues, inspired by https://github.com/friendica/friendica/pull/396

This commit is contained in:
friendica 2012-07-15 21:00:11 -07:00
parent 02d88e7cbe
commit f440d76200

View file

@ -100,11 +100,33 @@ function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d
return str_replace('1','0',$d->format($fmt));
}
$d = new DateTime($s, new DateTimeZone($from));
$d->setTimeZone(new DateTimeZone($to));
try {
$from_obj = new DateTimeZone($from);
}
catch(Exception $e) {
$from_obj = new DateTimeZone('UTC');
}
try {
$d = new DateTime($s, $from_obj);
}
catch(Exception $e) {
logger('datetime_convert: exception: ' . $e->getMessage());
$d = new DateTime('now', $from_obj);
}
try {
$to_obj = new DateTimeZone($to);
}
catch(Exception $e) {
$to_obj = new DateTimeZone('UTC');
}
$d->setTimeZone($to_obj);
return($d->format($fmt));
}}
// wrapper for date selector, tailored for use in birthday fields
function dob($dob) {