X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fdatetime.php;h=efcfa0a177eb8319e8feb6cd64033962efea333d;hb=a8aa99210206295aceeeb18f04bcf3650fe5a754;hp=75ae685f3ae2b3d23dfba2cdfe2a9db9bb1e235b;hpb=ba4db236ecff1ffdb56adc2715b3f53515f8cb34;p=friendica.git diff --git a/include/datetime.php b/include/datetime.php index 75ae685f3a..efcfa0a177 100644 --- a/include/datetime.php +++ b/include/datetime.php @@ -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) {