getTimestampTimeUnits() static public method

Split timestamp in time units
static public getTimestampTimeUnits ( $time ) : string
$time integer: timestamp
return string
Ejemplo n.º 1
0
 /**
  * Add a delay of a starting hour in a specific day
  *
  * @param $calendars_id    id of the calendar
  * @param $day             day number
  * @param $begin_time      begin time
  * @param $delay           timestamp delay to add
  *
  * @return timestamp value
  **/
 static function addDelayInDay($calendars_id, $day, $begin_time, $delay)
 {
     global $DB;
     $sum = 0;
     // Do not check hour if day before the end day of after the begin day
     $query = "SELECT GREATEST(`begin`,'{$begin_time}') AS BEGIN,\n                       TIMEDIFF(`end`,GREATEST(`begin`,'{$begin_time}')) AS TDIFF\n                FROM `glpi_calendarsegments`\n                WHERE `calendars_id` = '{$calendars_id}'\n                     AND `day` = '{$day}'\n                     AND ('{$begin_time}' < `end`)\n                ORDER BY `begin`";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result)) {
             while ($data = $DB->fetch_assoc($result)) {
                 list($hour, $minute, $second) = explode(':', $data['TDIFF']);
                 $tstamp = $hour * HOUR_TIMESTAMP + $minute * MINUTE_TIMESTAMP + $second;
                 // Delay is completed
                 if ($delay <= $tstamp) {
                     list($begin_hour, $begin_minute, $begin_second) = explode(':', $data['BEGIN']);
                     $beginstamp = $begin_hour * HOUR_TIMESTAMP + $begin_minute * MINUTE_TIMESTAMP + $begin_second;
                     $endstamp = $beginstamp + $delay;
                     $units = Toolbox::getTimestampTimeUnits($endstamp);
                     return str_pad($units['hour'], 2, '0', STR_PAD_LEFT) . ':' . str_pad($units['minute'], 2, '0', STR_PAD_LEFT) . ':' . str_pad($units['second'], 2, '0', STR_PAD_LEFT);
                 } else {
                     $delay -= $tstamp;
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Show for PDF an resources : tasks informations
  * 
  * @param $pdf object for the output
  * @param $ID of the resources
  */
 static function pdfForResource(PluginPdfSimplePDF $pdf, PluginResourcesResource $appli)
 {
     global $DB;
     $ID = $appli->fields['id'];
     if (!$appli->can($ID, "r")) {
         return false;
     }
     if (!plugin_resources_haveRight("resources", "r")) {
         return false;
     }
     $query = "SELECT * \n               FROM `glpi_plugin_resources_tasks` \n               WHERE `plugin_resources_resources_id` = '{$ID}'\n               AND `is_deleted` ='0'";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = $j = 0;
     $pdf->setColumnsSize(100);
     if ($number > 0) {
         $pdf->displayTitle('<b>' . self::getTypeName(2) . '</b>');
         $pdf->setColumnsSize(14, 14, 14, 14, 16, 14, 14);
         $pdf->displayTitle('<b><i>' . __('Name'), __('Type'), __('Comments'), __('Duration'), __('Planning'), __('Resource manager', 'resources'), __('Group') . '</i></b>');
         $i++;
         while ($j < $number) {
             $tID = $DB->result($result, $j, "id");
             $actiontime_ID = $DB->result($result, $j, "actiontime");
             $actiontime = '';
             $units = Toolbox::getTimestampTimeUnits($actiontime_ID);
             $hour = $units['hour'];
             $minute = $units['minute'];
             if ($hour) {
                 $actiontime = $hour . __('Hour', 'Hours', 2);
             }
             if ($minute || !$hour) {
                 $actiontime .= $minute . __('Minute', 'Minutes', 2);
             }
             $restrict = " `plugin_resources_tasks_id` = '" . $tID . "' ";
             $plans = getAllDatasFromTable("glpi_plugin_resources_taskplannings", $restrict);
             if (!empty($plans)) {
                 foreach ($plans as $plan) {
                     $planification = Html::convDateTime($plan["begin"]) . "&nbsp;->&nbsp;" . Html::convDateTime($plan["end"]);
                 }
             } else {
                 $planification = __('None');
             }
             $users_id = $DB->result($result, $j, "users_id");
             $managers = Html::clean(getUserName($users_id));
             $name = $DB->result($result, $j, "name");
             $task_type = $DB->result($result, $j, "plugin_resources_tasktypes_id");
             $comment = $DB->result($result, $j, "comment");
             $groups_id = $DB->result($result, $j, "groups_id");
             $pdf->displayLine(Html::clean($name), Html::clean(Dropdown::getDropdownName("glpi_plugin_resources_tasktypes", $task_type)), $comment, $actiontime, Html::clean($planification), $managers, Html::clean(Dropdown::getDropdownName("glpi_groups", $groups_id)));
             $j++;
         }
     } else {
         $pdf->displayLine(__('No item found'));
     }
     $pdf->displaySpace();
 }
Ejemplo n.º 3
0
 /**
  * Make a good string from the unix timestamp $sec
  *
  * @param $time         integer  timestamp
  * @param $display_sec  boolean  display seconds ? (true by default)
  * @param $use_days     boolean  use days for display ? (true by default)
  *
  * @return string
  **/
 static function timestampToString($time, $display_sec = true, $use_days = true)
 {
     $sign = '';
     if ($time < 0) {
         $sign = '- ';
         $time = abs($time);
     }
     $time = floor($time);
     // Force display seconds if time is null
     if ($time < MINUTE_TIMESTAMP) {
         $display_sec = true;
     }
     $units = Toolbox::getTimestampTimeUnits($time);
     if ($use_days) {
         if ($units['day'] > 0) {
             if ($display_sec) {
                 //TRANS: %1$s is the sign (-or empty), %2$d number of days, %3$d number of hours,
                 //       %4$d number of minutes, %5$d number of seconds
                 return sprintf(__('%1$s%2$d days %3$d hours %4$d minutes %5$d seconds'), $sign, $units['day'], $units['hour'], $units['minute'], $units['second']);
             }
             //TRANS:  %1$s is the sign (-or empty), %2$d number of days, %3$d number of hours,
             //        %4$d number of minutes
             return sprintf(__('%1$s%2$d days %3$d hours %4$d minutes'), $sign, $units['day'], $units['hour'], $units['minute']);
         }
     } else {
         if ($units['day'] > 0) {
             $units['hour'] += 24 * $units['day'];
         }
     }
     if ($units['hour'] > 0) {
         if ($display_sec) {
             //TRANS:  %1$s is the sign (-or empty), %2$d number of hours, %3$d number of minutes,
             //        %4$d number of seconds
             return sprintf(__('%1$s%2$d hours %3$d minutes %4$d seconds'), $sign, $units['hour'], $units['minute'], $units['second']);
         }
         //TRANS: %1$s is the sign (-or empty), %2$d number of hours, %3$d number of minutes
         return sprintf(__('%1$s%2$d hours %3$d minutes'), $sign, $units['hour'], $units['minute']);
     }
     if ($units['minute'] > 0) {
         if ($display_sec) {
             //TRANS:  %1$s is the sign (-or empty), %2$d number of minutes,  %3$d number of seconds
             return sprintf(__('%1$s%2$d minutes %3$d seconds'), $sign, $units['minute'], $units['second']);
         }
         //TRANS: %1$s is the sign (-or empty), %2$d number of minutes
         return sprintf(_n('%1$s%2$d minute', '%1$s%2$d minutes', $units['minute']), $sign, $units['minute']);
     }
     if ($display_sec) {
         //TRANS:  %1$s is the sign (-or empty), %2$d number of seconds
         return sprintf(_n('%1$s%2$s second', '%1$s%2$s seconds', $units['second']), $sign, $units['second']);
     }
     return '';
 }
Ejemplo n.º 4
0
 /**
  * Make a short string from the unix timestamp $sec
  * derived from html::timestampToString
  *
  * @param $time         integer  timestamp
  *
  * @return string
  **/
 static function timestampToStringShort($time)
 {
     $sign = '';
     if ($time < 0) {
         $sign = '- ';
         $time = abs($time);
     }
     $time = floor($time);
     $units = Toolbox::getTimestampTimeUnits($time);
     // if more than 24 hours
     if ($units['day'] > 0) {
         $units['hour'] += 24 * $units['day'];
     }
     //TRANS:  %1$s is the sign (-or empty), %2$d number of hours, %3$d number of minutes,
     //        %4$d number of seconds
     return sprintf('%1$s%2$02d:%3$02d:%4$02d', $sign, $units['hour'], $units['minute'], $units['second']);
 }