Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
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.
 
static get_list_of_timezones ($currentvalue=null, $include99=false)
 Returns a localised list of timezones.
 
static get_localised_timezone ($tz)
 Returns localised timezone name.
 
static get_server_timezone ()
 Returns server timezone.
 
static get_server_timezone_object ()
 Returns server timezone.
 
static get_user_timezone ($userorforcedtz=null)
 Returns user timezone.
 
static get_user_timezone_object ($userorforcedtz=null)
 Return user timezone object.
 
static normalise_timezone ($tz)
 Normalise the timezone name.
 
static phpunit_override_default_php_timezone ($tz)
 Do not use directly - use $this->setTimezone('xx', $tz) instead in your test case.
 
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 strftime (string $format, $timestamp=null, ?string $locale=null)
 Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible) This provides a cross-platform alternative to strftime() for when it will be removed from PHP.
 

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

◆ strftime()

static core_date::strftime ( string $format,
$timestamp = null,
?string $locale = null )
static

Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible) This provides a cross-platform alternative to strftime() for when it will be removed from PHP.

Note that output can be slightly different between libc sprintf and this function as it is using ICU.

From: https://github.com/alphp/strftime

Parameters
string$formatDate format
int | string | DateTime$timestampTimestamp
string | null$locale
Return values
string
Author
BohwaZ https://bohwaz.net/

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