Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

(no description)

File Size: 523 lines (18 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).

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

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.

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

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.

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

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

return: DateTime 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,

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.

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

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

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

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

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

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.

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

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

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

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?

return: bool
param: string $excelFormatCode

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

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

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

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

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

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

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

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