Browse Source

Avoid date 1970 see BT#12474

jmontoyaa 7 years ago
parent
commit
37826e84a7
2 changed files with 18 additions and 4 deletions
  1. 12 2
      main/inc/lib/internationalization.lib.php
  2. 6 2
      main/inc/lib/tracking.lib.php

+ 12 - 2
main/inc/lib/internationalization.lib.php

@@ -479,6 +479,12 @@ function api_get_local_time(
     }
     if (is_numeric($time)) {
         $time = intval($time);
+        if ($return_null_if_invalid_date) {
+            if (strtotime(date('d-m-Y H:i:s', $time)) !== (int) $time) {
+                return null;
+            }
+        }
+
         $from_timezone = 'UTC';
         $time = gmdate('Y-m-d H:i:s', $time);
     }
@@ -530,7 +536,7 @@ function api_strtotime($time, $timezone = null)
  * @author Ivan Tcholakov, 2009, code refactoring, adding support for predefined date/time formats.
  * @author Guillaume Viguier <guillaume.viguier@beeznest.com>
  *
- * @param mixed Timestamp or datetime string
+ * @param mixed $time Timestamp or datetime string
  * @param string|int Date format (see date formats in the Chamilo system:
  * TIME_NO_SEC_FORMAT,
  * DATE_FORMAT_SHORT,
@@ -544,6 +550,10 @@ function api_strtotime($time, $timezone = null)
  */
 function api_format_date($time, $format = null, $language = null)
 {
+    if (empty($time)) {
+        return '';
+    }
+
     $system_timezone = date_default_timezone_get();
     date_default_timezone_set(api_get_timezone());
 
@@ -726,7 +736,7 @@ function date_to_str_ago($date, $timeZone = 'UTC')
 function api_convert_and_format_date($time = null, $format = null, $from_timezone = null)
 {
     // First, convert the datetime to the right timezone
-    $time = api_get_local_time($time, null, $from_timezone);
+    $time = api_get_local_time($time, null, $from_timezone, true);
     // Second, localize the date
     return api_format_date($time, $format);
 }

+ 6 - 2
main/inc/lib/tracking.lib.php

@@ -3123,7 +3123,8 @@ class Tracking
 
             // Check the real number of LPs corresponding to the filter in the
             // database (and if no list was given, get them all)
-            $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND id = $lp_id ";
+            $sql = "SELECT id FROM $lp_table 
+                    WHERE c_id = $course_id AND id = $lp_id ";
             $res_row_lp = Database::query($sql);
             $count_row_lp = Database::num_rows($res_row_lp);
 
@@ -5518,7 +5519,10 @@ class Tracking
                     $time_spent_in_lp = api_time_to_hms($time_spent_in_lp);
                     $last_connection = '-';
                     if (!empty($last_connection_in_lp)) {
-                        $last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG);
+                        $last_connection = api_convert_and_format_date(
+                            $last_connection_in_lp,
+                            DATE_TIME_FORMAT_LONG
+                        );
                     }
 
                     $url = api_get_path(WEB_CODE_PATH)."lp/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id=$lp_id&action=view";