FusionDirectory
 All Data Structures Files Functions Variables
class_timezone.inc
Go to the documentation of this file.
1 <?php
2 
3 /*
4  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
5  Copyright (C) 2003-2010 Cajus Pollmeier
6  Copyright (C) 2011-2016 FusionDirectory
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
32 class timezone
33 {
34  /*
35  * \brief This function sets the default timezone according to fusiondirectory configuration.
36  *
37  * \return TRUE upon success, FALSE¬†otherwise
38  */
39  static public function setDefaultTimezoneFromConfig()
40  {
41  global $config;
42 
43  /* Is there a timezone set in the fusiondirectory configuration */
44  if ($config->get_cfg_value('timezone') != '') {
45  $tz = $config->get_cfg_value('timezone');
46 
47  if (@date_default_timezone_set($tz)) {
48  return TRUE;
49  } else {
51  _('Configuration error'),
52  sprintf(_('The timezone setting "%s" in your configuration is not valid.'), $tz),
53  ERROR_DIALOG
54  );
55  }
56  }
57  return FALSE;
58  }
59 
60  /*
61  * \brief This function returns the offset for the default timezone.
62  *
63  * deprecated
64  * \param $stamp is used to detect summer or winter time.
65  */
66  static public function get_default_timezone($stamp = NULL)
67  {
68  global $config;
69 
70  /* Use current timestamp if $stamp is not set */
71  if ($stamp === NULL) {
72  $stamp = time();
73  }
74 
75  /* Is there a correct timezone set in the fusiondirectory configuration */
76  if (static::setDefaultTimezoneFromConfig()) {
77  $tz = $config->get_cfg_value('timezone');
78  $tz_delta = date('Z', $stamp);
79  $tz_delta = $tz_delta / 3600;
80  return array('name' => $tz, 'value' => $tz_delta);
81  } else {
82  return array('name' => 'unconfigured', 'value' => 0);
83  }
84  }
85 
86  /*
87  * \brief Get the time zone informations
88  *
89  * \return Time zone informations
90  */
91  static public function _get_tz_zones()
92  {
93  return DateTimeZone::listIdentifiers();
94  }
95 
96  /* \brief Return default timezone as a DateTimeZone object */
97  static public function getDefaultTimeZone()
98  {
99  return new DateTimeZone(date_default_timezone_get());
100  }
101 
102  /* \brief Return UTC timezone as a DateTimeZone object */
103  static public function utc()
104  {
105  static $utc;
106  if (!isset($utc)) {
107  $utc = new DateTimeZone('UTC');
108  }
109  return $utc;
110  }
111 }
112 ?>
This class contains all the function needed to manage the timezones.
static display($s_title, $s_message, $i_type=INFO_DIALOG)
Display a message dialog.