mirror of https://github.com/MISP/MISP
43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
App::uses('AppHelper', 'View/Helper');
|
|
|
|
class TimeHelper extends AppHelper
|
|
{
|
|
/**
|
|
* @param string|int $time
|
|
* @return string
|
|
*/
|
|
public function time($time)
|
|
{
|
|
if (empty($time)) {
|
|
return '';
|
|
}
|
|
if (is_numeric($time)) {
|
|
$time = date('Y-m-d H:i:s', $time);
|
|
} else if (is_string($time)) { // time string with timezone
|
|
$timezonePosition = strpos($time, '+00:00'); // first and last seen format
|
|
if ($timezonePosition === false) {
|
|
$timezonePosition = strpos($time, '+0000'); // datetime attribute format
|
|
}
|
|
if ($timezonePosition !== false) {
|
|
return '<time title="' . __('In UTC') . '">' . h(substr($time, 0, $timezonePosition)) . '</time>';
|
|
}
|
|
}
|
|
|
|
return '<time>' . h($time) . '</time>';
|
|
}
|
|
|
|
/**
|
|
* @param int $date
|
|
* @return string
|
|
*/
|
|
public function date($date)
|
|
{
|
|
if (empty($date)) {
|
|
return '';
|
|
}
|
|
$date = date('Y-m-d', $date);
|
|
return '<time>' . h($date) . '</time>';
|
|
}
|
|
}
|