Moodle PHP Documentation 5.1
Moodle 5.1dev (Build: 20250711) (9addea9f0ac)
PhpOffice\PhpSpreadsheet\Shared\Date Class Reference

Static Public Member Functions

static convertIsoDate (mixed $value)
 
static dateTimeFromTimestamp (string $date, ?DateTimeZone $timeZone=null)
 
static dateTimeToExcel (DateTimeInterface $dateValue)
 Convert a PHP DateTime object to an MS Excel serialized date/time value.
 
static dayStringToNumber (string $day)
 Strips an ordinal from a numeric value.
 
static excelToDateTimeObject (float|int $excelTimestamp, null|DateTimeZone|string $timeZone=null)
 Convert a MS serialized datetime value from Excel to a PHP Date/Time object.
 
static excelToTimestamp ($excelTimestamp, $timeZone=null)
 Convert a MS serialized datetime value from Excel to a unix timestamp.
 
static formattedDateTimeFromTimestamp (string $date, string $format, ?DateTimeZone $timeZone=null)
 
static formattedPHPToExcel (int $year, int $month, int $day, int $hours=0, int $minutes=0, float|int $seconds=0)
 formattedPHPToExcel.
 
static getDefaultOrLocalTimezone ()
 Return the Default timezone, or local timezone if default is not set.
 
static getDefaultTimezone ()
 Return the Default timezone, or UTC if default not set.
 
static getDefaultTimezoneOrNull ()
 Return the Default timezone even if null.
 
static getExcelCalendar ()
 Return the Excel calendar (Windows 1900 or Mac 1904).
 
static isDateTime (Cell $cell, mixed $value=null, bool $dateWithoutTimeOkay=true)
 Is a given cell a date/time?
 
static isDateTimeFormat (NumberFormat $excelFormatCode, bool $dateWithoutTimeOkay=true)
 Is a given NumberFormat code a date/time format code?
 
static isDateTimeFormatCode (string $excelFormatCode, bool $dateWithoutTimeOkay=true)
 Is a given number format code a date/time?
 
static monthStringToNumber (string $monthName)
 Converts a month name (either a long or a short name) to a month number.
 
static PHPToExcel (mixed $dateValue)
 Convert a date from PHP to an MS Excel serialized date/time value.
 
static roundMicroseconds (DateTime $dti)
 Round the given DateTime object to seconds.
 
static setDefaultTimezone ($timeZone)
 Set the Default timezone to use for dates.
 
static setExcelCalendar (?int $baseYear)
 Set the Excel calendar (Windows 1900 or Mac 1904).
 
static stringToExcel (string $dateValue)
 Convert a date/time string to Excel time.
 
static timestampToExcel ($unixTimestamp)
 Convert a Unix timestamp to an MS Excel serialized date/time value.
 

Public Attributes

const CALENDAR_MAC_1904 = 1904
 
file home runner work phpdoc phpdoc moodle lib phpspreadsheet phpspreadsheet src PhpSpreadsheet Shared Date php const CALENDAR_WINDOWS_1900 = 1900
 constants
 

Static Public Attributes

static string[] array $monthNames
 Names of the months of the year, indexed by shortname Planned usage for locale settings.
 
static string[] array $numberSuffixes
 

Static Protected Attributes

static DateTimeZone $defaultTimeZone = null
 Default timezone to use for DateTime objects.
 
static int $excelCalendar = self::CALENDAR_WINDOWS_1900
 Base calendar year to use for calculations Value is either CALENDAR_WINDOWS_1900 (1900) or CALENDAR_MAC_1904 (1904).
 

Member Function Documentation

◆ convertIsoDate()

static PhpOffice\PhpSpreadsheet\Shared\Date::convertIsoDate ( mixed $value)
static
Parameters
mixed$valueConverts a date/time in ISO-8601 standard format date string to an Excel serialized timestamp. See https://en.wikipedia.org/wiki/ISO_8601 for details of the ISO-8601 standard format.

◆ dateTimeToExcel()

static PhpOffice\PhpSpreadsheet\Shared\Date::dateTimeToExcel ( DateTimeInterface $dateValue)
static

Convert a PHP DateTime object to an MS Excel serialized date/time value.

Parameters
DateTimeInterface$dateValuePHP DateTime object
Return values
floatMS Excel serialized date/time value

◆ dayStringToNumber()

static PhpOffice\PhpSpreadsheet\Shared\Date::dayStringToNumber ( string $day)
static

Strips an ordinal from a numeric value.

Parameters
string$dayDay number with an ordinal
Return values
int|stringThe integer value with any ordinal stripped, or the original string argument if it isn't a valid numeric

◆ excelToDateTimeObject()

static PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject ( float|int $excelTimestamp,
null|DateTimeZone|string $timeZone = null )
static

Convert a MS serialized datetime value from Excel to a PHP Date/Time object.

Parameters
float | int$excelTimestampMS Excel serialized date/time value
null | DateTimeZone | string$timeZoneThe timezone to assume for the Excel timestamp, if you don't want to treat it as a UTC value Use the default (UTC) unless you absolutely need a conversion
Return values
DateTimePHP date/time object

◆ excelToTimestamp()

static PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp ( $excelTimestamp,
$timeZone = null )
static

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.

Parameters
float | int$excelTimestampMS Excel serialized date/time value
null | DateTimeZone | string$timeZoneThe timezone to assume for the Excel timestamp, if you don't want to treat it as a UTC value Use the default (UTC) unless you absolutely need a conversion
Return values
intUnix timetamp for this date/time

◆ formattedPHPToExcel()

static PhpOffice\PhpSpreadsheet\Shared\Date::formattedPHPToExcel ( int $year,
int $month,
int $day,
int $hours = 0,
int $minutes = 0,
float|int $seconds = 0 )
static

formattedPHPToExcel.

Return values
floatExcel date/time value

◆ getExcelCalendar()

static PhpOffice\PhpSpreadsheet\Shared\Date::getExcelCalendar ( )
static

Return the Excel calendar (Windows 1900 or Mac 1904).

Return values
intExcel base date (1900 or 1904)

◆ monthStringToNumber()

static PhpOffice\PhpSpreadsheet\Shared\Date::monthStringToNumber ( string $monthName)
static

Converts a month name (either a long or a short name) to a month number.

Parameters
string$monthNameMonth name or abbreviation
Return values
int|stringMonth number (1 - 12), or the original string argument if it isn't a valid month name

◆ PHPToExcel()

static PhpOffice\PhpSpreadsheet\Shared\Date::PHPToExcel ( mixed $dateValue)
static

Convert a date from PHP to an MS Excel serialized date/time value.

Parameters
mixed$dateValuePHP DateTime object or a string - Unix timestamp is also permitted, but discouraged; not Y2038-safe on a 32-bit system, and no timezone info
Return values
false|floatExcel date/time value or boolean FALSE on failure

◆ setDefaultTimezone()

static PhpOffice\PhpSpreadsheet\Shared\Date::setDefaultTimezone ( $timeZone)
static

Set the Default timezone to use for dates.

Parameters
null | DateTimeZone | string$timeZoneThe timezone to set for all Excel datetimestamp to PHP DateTime Object conversions
Return values
boolSuccess or failure

◆ setExcelCalendar()

static PhpOffice\PhpSpreadsheet\Shared\Date::setExcelCalendar ( ?int $baseYear)
static

Set the Excel calendar (Windows 1900 or Mac 1904).

Parameters
?int$baseYearExcel base date (1900 or 1904)
Return values
boolSuccess or failure

◆ stringToExcel()

static PhpOffice\PhpSpreadsheet\Shared\Date::stringToExcel ( string $dateValue)
static

Convert a date/time string to Excel time.

Parameters
string$dateValueExamples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
Return values
false|floatExcel date/time serial value

◆ timestampToExcel()

static PhpOffice\PhpSpreadsheet\Shared\Date::timestampToExcel ( $unixTimestamp)
static

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.

Parameters
float | int | string$unixTimestampUnix Timestamp
Return values
false|floatMS Excel serialized date/time value

Member Data Documentation

◆ $monthNames

string [] array PhpOffice\PhpSpreadsheet\Shared\Date::$monthNames
static
Initial value:
= [
'Jan' => 'January',
'Feb' => 'February',
'Mar' => 'March',
'Apr' => 'April',
'May' => 'May',
'Jun' => 'June',
'Jul' => 'July',
'Aug' => 'August',
'Sep' => 'September',
'Oct' => 'October',
'Nov' => 'November',
'Dec' => 'December',
]

Names of the months of the year, indexed by shortname Planned usage for locale settings.

◆ $numberSuffixes

string [] array PhpOffice\PhpSpreadsheet\Shared\Date::$numberSuffixes
static
Initial value:
= [
'st',
'nd',
'rd',
'th',
]

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