Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
core_date Class Reference

Core date and time related code. More...

Static Public Member Functions

static get_default_php_timezone ()
 Return default timezone set in php.ini or config.php. More...
 
static get_list_of_timezones ($currentvalue=null, $include99=false)
 Returns a localised list of timezones. More...
 
static get_localised_timezone ($tz)
 Returns localised timezone name. More...
 
static get_server_timezone ()
 Returns server timezone. More...
 
static get_server_timezone_object ()
 Returns server timezone. More...
 
static get_user_timezone ($userorforcedtz=null)
 Returns user timezone. More...
 
static get_user_timezone_object ($userorforcedtz=null)
 Return user timezone object. More...
 
static normalise_timezone ($tz)
 Normalise the timezone name. More...
 
static phpunit_override_default_php_timezone ($tz)
 Do not use directly - use $this->setTimezone('xx', $tz) instead in your test case. More...
 
static phpunit_reset ()
 To be called from phpunit reset only, after restoring $CFG.
 
static set_default_server_timezone ()
 Set PHP default timezone to $CFG->timezone.
 
static store_default_php_timezone ()
 To be called from lib/setup.php only!
 

Static Protected Member Functions

static init_zones ()
 Initialise timezone arrays, call before use.
 

Static Protected Attributes

static array $badzones = null
 mapping of timezones not supported by PHP
 
static array $bczones = null
 list of BC zones supported by PHP
 
static string $defaultphptimezone = null
 the default PHP timezone right after config.php
 
static array $goodzones = null
 list of recommended zones
 

Detailed Description

Core date and time related code.

Since
Moodle 2.9
License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Author
Petr Skoda petr..nosp@m.skod.nosp@m.a@tot.nosp@m.aral.nosp@m.ms.co.nosp@m.m

Member Function Documentation

◆ get_default_php_timezone()

static core_date::get_default_php_timezone ( )
static

Return default timezone set in php.ini or config.php.

Return values
stringnormalised timezone compatible with PHP

◆ get_list_of_timezones()

static core_date::get_list_of_timezones (   $currentvalue = null,
  $include99 = false 
)
static

Returns a localised list of timezones.

Parameters
string$currentvalue
bool$include99should the server timezone info be included?
Return values
array

◆ get_localised_timezone()

static core_date::get_localised_timezone (   $tz)
static

Returns localised timezone name.

Parameters
string$tz
Return values
string

◆ get_server_timezone()

static core_date::get_server_timezone ( )
static

Returns server timezone.

Return values
stringnormalised timezone name compatible with PHP

◆ get_server_timezone_object()

static core_date::get_server_timezone_object ( )
static

Returns server timezone.

Return values
DateTimeZone

◆ get_user_timezone()

static core_date::get_user_timezone (   $userorforcedtz = null)
static

Returns user timezone.

Ideally the parameter should be a real user record, unfortunately the legacy code is using 99 for both server and default value.

Example of using legacy API: // Date for other user via legacy API. $datestr = userdate($time, core_date::get_user_timezone($user));

The coding style rules in Moodle are moronic, why cannot the parameter names have underscores in them?

Parameters
mixed$userorforcedtzuser object or legacy forced timezone string or tz object
Return values
stringnormalised timezone name compatible with PHP

◆ get_user_timezone_object()

static core_date::get_user_timezone_object (   $userorforcedtz = null)
static

Return user timezone object.

Parameters
mixed$userorforcedtz
Return values
DateTimeZone

◆ normalise_timezone()

static core_date::normalise_timezone (   $tz)
static

Normalise the timezone name.

If timezone not supported this method falls back to server timezone (if valid) or default PHP timezone.

Parameters
int | string | float | DateTimeZone$tz
Return values
stringtimezone compatible with PHP

◆ phpunit_override_default_php_timezone()

static core_date::phpunit_override_default_php_timezone (   $tz)
static

Do not use directly - use $this->setTimezone('xx', $tz) instead in your test case.

Parameters
string$tzvalid timezone name

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