ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TimeZone.php
Go to the documentation of this file.
1 <?php
2 
4 
5 use DateTimeZone;
7 
8 class TimeZone
9 {
15  protected static $timezone = 'UTC';
16 
24  private static function validateTimeZone($timezone)
25  {
26  return in_array($timezone, DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC));
27  }
28 
36  public static function setTimeZone($timezone)
37  {
38  if (self::validateTimezone($timezone)) {
39  self::$timezone = $timezone;
40 
41  return true;
42  }
43 
44  return false;
45  }
46 
52  public static function getTimeZone()
53  {
54  return self::$timezone;
55  }
56 
66  public static function getTimeZoneAdjustment($timezone, $timestamp)
67  {
68  $timezone = $timezone ?? self::$timezone;
69  $dtobj = Date::dateTimeFromTimestamp("$timestamp");
70  if (!self::validateTimezone($timezone)) {
71  throw new PhpSpreadsheetException("Invalid timezone $timezone");
72  }
73  $dtobj->setTimeZone(new DateTimeZone($timezone));
74 
75  return $dtobj->getOffset();
76  }
77 }
static validateTimeZone($timezone)
Validate a Timezone name.
Definition: TimeZone.php:24
static setTimeZone($timezone)
Set the Default Timezone used for date/time conversions.
Definition: TimeZone.php:36
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:81
static getTimeZoneAdjustment($timezone, $timestamp)
Return the Timezone offset used for date/time conversions to/from UST This requires both the timezone...
Definition: TimeZone.php:66
static getTimeZone()
Return the Default Timezone used for date/time conversions.
Definition: TimeZone.php:52