Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

(no description)

File Size: 556 lines (19 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: Date  - X-Ref

setExcelCalendar($baseYear)   X-Ref
Set the Excel calendar (Windows 1900 or Mac 1904).

param: int $baseYear Excel base date (1900 or 1904)
return: bool Success or failure

getExcelCalendar()   X-Ref
Return the Excel calendar (Windows 1900 or Mac 1904).

return: int Excel base date (1900 or 1904)

setDefaultTimezone($timeZone)   X-Ref
Set the Default timezone to use for dates.

param: null|DateTimeZone|string $timeZone The timezone to set for all Excel datetimestamp to PHP DateTime Object conversions
return: bool Success or failure

getDefaultTimezone()   X-Ref
Return the Default timezone, or UTC if default not set.


getDefaultOrLocalTimezone()   X-Ref
Return the Default timezone, or local timezone if default is not set.


getDefaultTimezoneOrNull()   X-Ref
Return the Default timezone even if null.


validateTimeZone($timeZone)   X-Ref
Validate a timezone.

param: null|DateTimeZone|string $timeZone The timezone to validate, either as a timezone string or object
return: ?DateTimeZone The timezone as a timezone object

convertIsoDate($value)   X-Ref

param: mixed $value
return: float|int

excelToDateTimeObject($excelTimestamp, $timeZone = null)   X-Ref
Convert a MS serialized datetime value from Excel to a PHP Date/Time object.

param: float|int $excelTimestamp MS Excel serialized date/time value
param: null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp,
return: DateTime PHP date/time object

excelToTimestamp($excelTimestamp, $timeZone = null)   X-Ref
Convert a MS serialized datetime value from Excel to a unix timestamp.
The use of Unix timestamps, and therefore this function, is discouraged.
They are not Y2038-safe on a 32-bit system, and have no timezone info.

param: float|int $excelTimestamp MS Excel serialized date/time value
param: null|DateTimeZone|string $timeZone The timezone to assume for the Excel timestamp,
return: int Unix timetamp for this date/time

PHPToExcel($dateValue)   X-Ref
Convert a date from PHP to an MS Excel serialized date/time value.

param: mixed $dateValue PHP DateTime object or a string - Unix timestamp is also permitted, but discouraged;
return: false|float Excel date/time value

dateTimeToExcel(DateTimeInterface $dateValue)   X-Ref
Convert a PHP DateTime object to an MS Excel serialized date/time value.

param: DateTimeInterface $dateValue PHP DateTime object
return: float MS Excel serialized date/time value

timestampToExcel($unixTimestamp)   X-Ref
Convert a Unix timestamp to an MS Excel serialized date/time value.
The use of Unix timestamps, and therefore this function, is discouraged.
They are not Y2038-safe on a 32-bit system, and have no timezone info.

param: int $unixTimestamp Unix Timestamp
return: false|float MS Excel serialized date/time value

formattedPHPToExcel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)   X-Ref
formattedPHPToExcel.

param: int $year
param: int $month
param: int $day
param: int $hours
param: int $minutes
param: int $seconds
return: float Excel date/time value

isDateTime(Cell $cell)   X-Ref
Is a given cell a date/time?

return: bool

isDateTimeFormat(NumberFormat $excelFormatCode)   X-Ref
Is a given number format a date/time?

return: bool

isDateTimeFormatCode($excelFormatCode)   X-Ref
Is a given number format code a date/time?

param: string $excelFormatCode
return: bool

stringToExcel($dateValue)   X-Ref
Convert a date/time string to Excel time.

param: string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
return: false|float Excel date/time serial value

monthStringToNumber($monthName)   X-Ref
Converts a month name (either a long or a short name) to a month number.

param: string $monthName Month name or abbreviation
return: int|string Month number (1 - 12), or the original string argument if it isn't a valid month name

dayStringToNumber($day)   X-Ref
Strips an ordinal from a numeric value.

param: string $day Day number with an ordinal
return: int|string The integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric

dateTimeFromTimestamp(string $date, ?DateTimeZone $timeZone = null)   X-Ref
No description

formattedDateTimeFromTimestamp(string $date, string $format, ?DateTimeZone $timeZone = null)   X-Ref
No description