ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilCertificateDateHelper Class Reference
+ Collaboration diagram for ilCertificateDateHelper:

Public Member Functions

 __construct ()
 
 formatDate ($raw_date_input, ?ilObjUser $user=null, ?int $date_format=null)
 
 formatDateTime ($raw_datetime_input, ?ilObjUser $user=null, ?int $datetime_format=null)
 

Private Member Functions

 format ($raw, ?ilObjUser $user, int $format, bool $has_time)
 
 autoDetectFormat ($value, int $default_when_not_unix)
 
 assertFormatMatchesInput ($value, int $format)
 
 isProbablyUnixTimestamp ($maybe_timestamp)
 

Detailed Description

Definition at line 21 of file ilCertificateDateHelper.php.

Constructor & Destructor Documentation

◆ __construct()

ilCertificateDateHelper::__construct ( )

Definition at line 23 of file ilCertificateDateHelper.php.

24 {
25 class_exists('ilDateTime'); // Ensure all global constants are defined
26 }

Member Function Documentation

◆ assertFormatMatchesInput()

ilCertificateDateHelper::assertFormatMatchesInput (   $value,
int  $format 
)
private
Parameters
string | int$value
Exceptions
InvalidArgumentException

Definition at line 104 of file ilCertificateDateHelper.php.

104 : void
105 {
106 $is_unix_like = $this->isProbablyUnixTimestamp($value);
107
108 if ($format === IL_CAL_UNIX && !$is_unix_like) {
109 throw new InvalidArgumentException('Non-numeric input given for IL_CAL_UNIX');
110 }
111
112 if ($format !== IL_CAL_UNIX && $is_unix_like) {
113 throw new InvalidArgumentException('Unix timestamp given but format is not IL_CAL_UNIX');
114 }
115 }
const IL_CAL_UNIX
isProbablyUnixTimestamp($maybe_timestamp)

References IL_CAL_UNIX, and isProbablyUnixTimestamp().

Referenced by format().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ autoDetectFormat()

ilCertificateDateHelper::autoDetectFormat (   $value,
int  $default_when_not_unix 
)
private
Parameters
string | int$value

Definition at line 95 of file ilCertificateDateHelper.php.

95 : int
96 {
97 return $this->isProbablyUnixTimestamp($value) ? IL_CAL_UNIX : $default_when_not_unix;
98 }

References IL_CAL_UNIX, and isProbablyUnixTimestamp().

Referenced by formatDate(), and formatDateTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ format()

ilCertificateDateHelper::format (   $raw,
?ilObjUser  $user,
int  $format,
bool  $has_time 
)
private
Parameters
int | string$raw
Exceptions
ilDateTimeException
InvalidArgumentException

Definition at line 63 of file ilCertificateDateHelper.php.

63 : string
64 {
65 $this->assertFormatMatchesInput($raw, $format);
66
67 if ($format === IL_CAL_UNIX) {
68 $raw = (int) $raw;
69 } else {
70 $raw = (string) $raw;
71 }
72
75 try {
76 $dateObj = $has_time
77 ? new ilDateTime($raw, $format)
78 : new ilDate($raw, $format);
79
81 $dateObj,
82 false,
83 false,
84 false,
85 $user
86 );
87 } finally {
89 }
90 }
assertFormatMatchesInput($value, int $format)
static setUseRelativeDates(bool $a_status)
set use relative dates
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
Class for single dates.

References assertFormatMatchesInput(), ilDatePresentation\formatDate(), IL_CAL_UNIX, ILIAS\Repository\int(), ilDatePresentation\setUseRelativeDates(), and ilDatePresentation\useRelativeDates().

Referenced by formatDate(), and formatDateTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatDate()

ilCertificateDateHelper::formatDate (   $raw_date_input,
?ilObjUser  $user = null,
?int  $date_format = null 
)
Parameters
string | int$raw_date_input
Exceptions
ilDateTimeException
InvalidArgumentException

Definition at line 33 of file ilCertificateDateHelper.php.

33 : string
34 {
35 return $this->format(
36 $raw_date_input,
37 $user,
38 $date_format ?? $this->autoDetectFormat($raw_date_input, IL_CAL_DATE),
39 false
40 );
41 }
const IL_CAL_DATE
autoDetectFormat($value, int $default_when_not_unix)
format($raw, ?ilObjUser $user, int $format, bool $has_time)

References autoDetectFormat(), format(), and IL_CAL_DATE.

Referenced by ilCertificateDateHelperTest\testExplicitFormatsWorkAsExpected().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ formatDateTime()

ilCertificateDateHelper::formatDateTime (   $raw_datetime_input,
?ilObjUser  $user = null,
?int  $datetime_format = null 
)
Parameters
string | int$raw_datetime_input
Exceptions
ilDateTimeException
InvalidArgumentException

Definition at line 48 of file ilCertificateDateHelper.php.

48 : string
49 {
50 return $this->format(
51 $raw_datetime_input,
52 $user,
53 $datetime_format ?? $this->autoDetectFormat($raw_datetime_input, IL_CAL_DATETIME),
54 true
55 );
56 }
const IL_CAL_DATETIME

References autoDetectFormat(), format(), and IL_CAL_DATETIME.

+ Here is the call graph for this function:

◆ isProbablyUnixTimestamp()

ilCertificateDateHelper::isProbablyUnixTimestamp (   $maybe_timestamp)
private
Parameters
int | string$maybe_timestamp

Definition at line 120 of file ilCertificateDateHelper.php.

120 : bool
121 {
122 if (is_int($maybe_timestamp)) {
123 return true;
124 }
125
126 if (!is_string($maybe_timestamp) || !ctype_digit($maybe_timestamp)) {
127 return false;
128 }
129
130 try {
131 $datetime = DateTimeImmutable::createFromFormat('Ymd', $maybe_timestamp);
132 return $datetime === false;
133 } catch (Throwable) {
134 // Fallthrough
135 }
136
137 return true;
138 }
$datetime

References $datetime.

Referenced by assertFormatMatchesInput(), and autoDetectFormat().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: