3 declare(strict_types=1);
55 self::$use_relative_dates = $a_status;
60 return self::$use_relative_dates;
72 $lng = $DIC->language();
83 $lng = $DIC->language();
84 self::setLanguage(
$lng);
85 self::setUseRelativeDates(
true);
88 public static function formatDate(
ilDateTime $date,
bool $a_skip_day =
false,
bool $a_include_wd =
false,
bool $include_seconds =
false): string
93 $lng->loadLanguageModule(
'dateplaner');
100 $has_time = !is_a($date,
'ilDate');
113 if (self::isToday($date) and self::useRelativeDates()) {
115 } elseif (self::isTomorrow($date) and self::useRelativeDates()) {
117 } elseif (self::isYesterday($date) and self::useRelativeDates()) {
122 $date_str =
$lng->txt(self::$weekdays[$date_info[
'wday']]) .
", ";
124 $date_str .= $date_info[
'mday'] .
'. ' .
136 $sec = ($include_seconds)
140 switch (
$ilUser->getTimeFormat()) {
162 $has_time = !is_a($start,
'ilDate');
167 return self::formatDate($start);
171 if (!$a_skip_starting_day) {
172 $date_str = self::formatDate(
180 switch (
$ilUser->getTimeFormat()) {
188 switch (
$ilUser->getTimeFormat()) {
190 return $date_str . $sep . $start->
get(
198 return $date_str . $sep . $start->
get(
209 return self::formatDate($start, $a_skip_starting_day) .
' - ' . self::formatDate($end);
221 if (!is_object(self::$today)) {
235 if (!is_object(self::$yesterday)) {
251 if (!is_object(self::$tomorrow)) {
265 bool $force_with_seconds =
false,
277 $seconds = $seconds ?: 0;
281 $days = floor($seconds / 86400);
282 $rest = $seconds % 86400;
284 $hours = floor(
$rest / 3600);
287 $minutes = floor(
$rest / 60);
288 $seconds =
$rest % 60;
290 $days = ceil($seconds / 86400);
291 $rest = $seconds % 86400;
293 $hours = ceil(
$rest / 3600);
296 $minutes = ceil(
$rest / 60);
297 $seconds =
$rest % 60;
301 $message = $days .
' ' . ($days == 1 ?
$lng->txt(
'day') :
$lng->txt(
'days'));
307 $message .= ($hours .
' ' . ($hours == 1 ?
$lng->txt(
'hour') :
$lng->txt(
'hours')));
313 $message .= ($minutes .
' ' . ($minutes == 1 ?
$lng->txt(
'minute') :
$lng->txt(
'minutes')));
315 if ($force_with_seconds && $seconds) {
319 $message .= ($seconds .
' ' . ($seconds == 1 ?
$lng->txt(
'second') :
$lng->txt(
'seconds')));
321 if (!$days and !$hours and !$minutes) {
322 return $seconds .
' ' . ($seconds == 1 ?
$lng->txt(
'second') :
$lng->txt(
'seconds'));
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
static _numericMonthToString(int $a_month, bool $a_long=true)
numeric month to string
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
static resetToDefaults()
reset to defaults
static isToday(ilDateTime $date)
Check if date is "today".
static setLanguage(ilLanguage $a_lng)
static secondsToString(int $seconds, bool $force_with_seconds=false, ?ilLanguage $a_lng=null)
converts seconds to string: Long: 7 days 4 hour(s) ...
static useRelativeDates()
static bool $use_relative_dates
static isYesterday(ilDateTime $date)
Check if date is yesterday.
static isTomorrow(ilDateTime $date)
Check if date is tomorrow.
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
static ilDateTime $tomorrow
static _equals(ilDateTime $start, ilDateTime $end, string $a_compare_field='', string $a_tz='')
Check if two date are equal.
static setUseRelativeDates(bool $a_status)
set use relative dates
isNull()
Check if a date is null (Datetime == '0000-00-00 00:00:00', unixtime == 0,...)
static ilDateTime $yesterday