Browse Source

Merge branch 'aragonc-1.11.x' into 1.11.x

Yannick Warnier 8 years ago
parent
commit
1e2db25277
1 changed files with 25 additions and 14 deletions
  1. 25 14
      main/inc/lib/internationalization.lib.php

+ 25 - 14
main/inc/lib/internationalization.lib.php

@@ -432,7 +432,7 @@ function api_get_local_time(
     $from_timezone = null,
     $return_null_if_invalid_date = false,
     $showTime = true,
-    $dateHuman = false
+    $humanForm = false
 ) {
     // Determining the timezone to be converted from
     if (is_null($from_timezone)) {
@@ -462,19 +462,7 @@ function api_get_local_time(
     try {
         $date = new DateTime($time, new DateTimezone($from_timezone));
         $date->setTimezone(new DateTimeZone($to_timezone));
-        if ($showTime) {
-            if ($dateHuman) {
-               return $date->format('j M Y H:i:s');    
-            } else {
-               return $date->format('Y-m-d H:i:s');     
-            }
-        } else {
-            if ($dateHuman) {
-               return $date->format('j M Y');    
-            } else {
-               return $date->format('Y-m-d');     
-            }
-        }
+        return apiGetHumanDateTime($date, $showTime, $humanForm);
     } catch (Exception $e) {
         return null;
     }
@@ -1966,3 +1954,26 @@ function _api_convert_encoding_supports($encoding) {
     }
     return $supports[$encoding];
 }
+
+/**
+ * Given a date object, return a human or ISO format, with or without h:m:s
+ * @param object $date The Date object
+ * @param bool $showTime Whether to show the time and date (true) or only the date (false)
+ * @param bool $humanForm Whether to show day-month-year (true) or year-month-day (false)
+ * @return string Formatted date
+ */
+function apiGetHumanDateTime($date, $showTime = true, $humanForm = false) {
+    if ($showTime) {
+        if ($dateHuman) {
+           return $date->format('j M Y H:i:s');    
+        } else {
+           return $date->format('Y-m-d H:i:s');     
+        }
+    } else {
+        if ($dateHuman) {
+           return $date->format('j M Y');    
+        } else {
+           return $date->format('Y-m-d');     
+        }
+    }
+}