ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 12 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 31 of file Time.php.

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

32  {
33  if ($instant === null) {
34  $instant = time();
35  }
36  return gmdate('Y-m-d\TH:i:s\Z', $instant);
37  }
+ 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

Definition at line 51 of file Time.php.

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

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

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

Definition at line 91 of file Time.php.

References $timestamp.

Referenced by SimpleSAML_Utilities\parseDuration().

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

Field Documentation

◆ $tz_initialized

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

Definition at line 20 of file Time.php.


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