aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/datetime.php25
1 files changed, 23 insertions, 2 deletions
diff --git a/include/datetime.php b/include/datetime.php
index 75ae685f3..9f145e5c7 100644
--- a/include/datetime.php
+++ b/include/datetime.php
@@ -100,8 +100,29 @@ 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 = newDateTime('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));
}}