ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SimpleSAML\Utils\Time Class Reference
+ Collaboration diagram for SimpleSAML\Utils\Time:

Static Public Member Functions

static generateTimestamp ($instant=null)
 This function generates a timestamp on the form used by the SAML protocols. More...
 
static initTimezone ()
 Initialize the timezone. More...
 
static parseDuration ($duration, $timestamp=null)
 Interpret a ISO8601 duration value relative to a given timestamp. More...
 

Static Private Attributes

static $tz_initialized = false
 

Detailed Description

Definition at line 13 of file Time.php.

Member Function Documentation

◆ generateTimestamp()

static SimpleSAML\Utils\Time::generateTimestamp (   $instant = null)
static

This function generates a timestamp on the form used by the SAML protocols.

Parameters
int$instantThe time the timestamp should represent. Defaults to current time.
Returns
string The timestamp.
Author
Olav Morken, UNINETT AS olav..nosp@m.mork.nosp@m.en@un.nosp@m.inet.nosp@m.t.no

Definition at line 32 of file Time.php.

33 {
34 if ($instant === null) {
35 $instant = time();
36 }
37 return gmdate('Y-m-d\TH:i:s\Z', $instant);
38 }

Referenced by SimpleSAML\Bindings\Shib13\Artifact\buildRequest(), SimpleSAML\XML\Shib13\AuthnResponse\generate(), sspmod_adfs_IdP_ADFS\generateResponse(), and SimpleSAML_Utilities\generateTimestamp().

+ Here is the caller graph for this function:

◆ initTimezone()

static SimpleSAML\Utils\Time::initTimezone ( )
static

Initialize the timezone.

This function should be called before any calls to date().

Author
Olav Morken, UNINETT AS olav..nosp@m.mork.nosp@m.en@un.nosp@m.inet.nosp@m.t.no
Exceptions

SimpleSAML_Error_Exception If the timezone set in the configuration is invalid.

Returns
void

Definition at line 52 of file Time.php.

53 {
54 if (self::$tz_initialized) {
55 return;
56 }
57
59
60 $timezone = $globalConfig->getString('timezone', null);
61 if ($timezone !== null) {
62 if (!date_default_timezone_set($timezone)) {
63 throw new \SimpleSAML_Error_Exception('Invalid timezone set in the "timezone" option in config.php.');
64 }
65 self::$tz_initialized = true;
66 return;
67 }
68 // we don't have a timezone configured
69
70 Logger::maskErrors(E_ALL);
71 $serverTimezone = date_default_timezone_get();
73
74 // set the timezone to the default
75 date_default_timezone_set($serverTimezone);
76 self::$tz_initialized = true;
77 }
static popErrorMask()
Pop an error mask.
Definition: Logger.php:324
static maskErrors($mask)
Disable error reporting for the given log levels.
Definition: Logger.php:306
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
$globalConfig

References $globalConfig, SimpleSAML_Configuration\getInstance(), SimpleSAML\Logger\maskErrors(), and SimpleSAML\Logger\popErrorMask().

Referenced by SimpleSAML\Logger\FileLoggingHandler\__construct(), and SimpleSAML_Utilities\initTimezone().

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

◆ parseDuration()

static SimpleSAML\Utils\Time::parseDuration (   $duration,
  $timestamp = null 
)
static

Interpret a ISO8601 duration value relative to a given timestamp.

Please note no fractions are allowed, neither durations specified in the formats PYYYYMMDDThhmmss nor P[YYYY]-[MM]-[DD]T[hh]:[mm]:[ss].

Parameters
string$durationThe duration, as a string.
int$timestampThe unix timestamp we should apply the duration to. Optional, default to the current time.
Returns
int The new timestamp, after the duration is applied.
Exceptions

InvalidArgumentException If $duration is not a valid ISO 8601 duration or if the input parameters do not have the right data types.

Definition at line 92 of file Time.php.

93 {
94 if (!(is_string($duration) && (is_int($timestamp) || is_null($timestamp)))) {
95 throw new \InvalidArgumentException('Invalid input parameters');
96 }
97
98 // parse the duration. We use a very strict pattern
99 $durationRegEx = '#^(-?)P(?:(?:(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)'.
100 '(?:[.,]\d+)?S)?)?)|(?:(\\d+)W))$#D';
101 if (!preg_match($durationRegEx, $duration, $matches)) {
102 throw new \InvalidArgumentException('Invalid ISO 8601 duration: '.$duration);
103 }
104
105 $durYears = (empty($matches[2]) ? 0 : (int) $matches[2]);
106 $durMonths = (empty($matches[3]) ? 0 : (int) $matches[3]);
107 $durDays = (empty($matches[4]) ? 0 : (int) $matches[4]);
108 $durHours = (empty($matches[5]) ? 0 : (int) $matches[5]);
109 $durMinutes = (empty($matches[6]) ? 0 : (int) $matches[6]);
110 $durSeconds = (empty($matches[7]) ? 0 : (int) $matches[7]);
111 $durWeeks = (empty($matches[8]) ? 0 : (int) $matches[8]);
112
113 if (!empty($matches[1])) {
114 // negative
115 $durYears = -$durYears;
116 $durMonths = -$durMonths;
117 $durDays = -$durDays;
118 $durHours = -$durHours;
119 $durMinutes = -$durMinutes;
120 $durSeconds = -$durSeconds;
121 $durWeeks = -$durWeeks;
122 }
123
124 if ($timestamp === null) {
125 $timestamp = time();
126 }
127
128 if ($durYears !== 0 || $durMonths !== 0) {
129 /* Special handling of months and years, since they aren't a specific interval, but
130 * instead depend on the current time.
131 */
132
133 /* We need the year and month from the timestamp. Unfortunately, PHP doesn't have the
134 * gmtime function. Instead we use the gmdate function, and split the result.
135 */
136 $yearmonth = explode(':', gmdate('Y:n', $timestamp));
137 $year = (int) ($yearmonth[0]);
138 $month = (int) ($yearmonth[1]);
139
140 // remove the year and month from the timestamp
141 $timestamp -= gmmktime(0, 0, 0, $month, 1, $year);
142
143 // add years and months, and normalize the numbers afterwards
144 $year += $durYears;
145 $month += $durMonths;
146 while ($month > 12) {
147 $year += 1;
148 $month -= 12;
149 }
150 while ($month < 1) {
151 $year -= 1;
152 $month += 12;
153 }
154
155 // add year and month back into timestamp
156 $timestamp += gmmktime(0, 0, 0, $month, 1, $year);
157 }
158
159 // add the other elements
160 $timestamp += $durWeeks * 7 * 24 * 60 * 60;
161 $timestamp += $durDays * 24 * 60 * 60;
162 $timestamp += $durHours * 60 * 60;
163 $timestamp += $durMinutes * 60;
164 $timestamp += $durSeconds;
165
166 return $timestamp;
167 }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81

References $timestamp.

Referenced by SimpleSAML_Utilities\parseDuration().

+ Here is the caller graph for this function:

Field Documentation

◆ $tz_initialized

SimpleSAML\Utils\Time::$tz_initialized = false
staticprivate

Definition at line 21 of file Time.php.


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