| | <?php |
| |
|
| | namespace Kanboard\Helper; |
| |
|
| | use DateTime; |
| | use Kanboard\Core\Base; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | class DateHelper extends Base |
| | { |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function time($value) |
| | { |
| | return date($this->configModel->get('application_time_format', 'H:i'), $value); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function date($value) |
| | { |
| | if (empty($value)) { |
| | return ''; |
| | } |
| |
|
| | if (! ctype_digit((string) $value)) { |
| | $value = strtotime($value); |
| | } |
| |
|
| | return date($this->configModel->get('application_date_format', 'm/d/Y'), $value); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function datetime($value) |
| | { |
| | return date($this->dateParser->getUserDateTimeFormat(), $value); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function duration($seconds) |
| | { |
| | if ($seconds == 0) { |
| | return 0; |
| | } |
| |
|
| | $dtF = new DateTime("@0"); |
| | $dtT = new DateTime("@$seconds"); |
| |
|
| | $format = sprintf("%%a %s, %%h %s, %%i %s, %%s %s", t('days'), t('hours'), t('minutes'), t('seconds')); |
| | return $dtF->diff($dtT)->format($format); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function durationHours($hours) |
| | { |
| | return sprintf('%0.2f %s', round($hours, 2), t('hours')); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function age($timestamp, $now = null) |
| | { |
| | if ($now === null) { |
| | $now = time(); |
| | } |
| |
|
| | $diff = $now - $timestamp; |
| |
|
| | if ($diff < 900) { |
| | return t('<15m'); |
| | } |
| | if ($diff < 1200) { |
| | return t('<30m'); |
| | } elseif ($diff < 3600) { |
| | return t('<1h'); |
| | } elseif ($diff < 86400) { |
| | return '~'.t('%dh', $diff / 3600); |
| | } |
| |
|
| | return t('%dd', ($now - $timestamp) / 86400); |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getDayHours() |
| | { |
| | $values = array(); |
| |
|
| | foreach (range(0, 23) as $hour) { |
| | foreach (array(0, 30) as $minute) { |
| | $time = sprintf('%02d:%02d', $hour, $minute); |
| | $values[$time] = $time; |
| | } |
| | } |
| |
|
| | return $values; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getWeekDays() |
| | { |
| | $values = array(); |
| |
|
| | foreach (range(1, 7) as $day) { |
| | $values[$day] = $this->getWeekDay($day); |
| | } |
| |
|
| | return $values; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | public function getWeekDay($day) |
| | { |
| | return date('l', strtotime('next Monday +'.($day - 1).' days')); |
| | } |
| | } |
| |
|