DateTimeParser
in package
DateTimeParser.
This class is responsible for parsing the several different date and time formats iCalendar and vCards have.
Tags
Table of Contents
- parse() : DateTimeImmutable|DateInterval
- Parses either a Date or DateTime, or Duration value.
- parseDate() : DateTimeImmutable
- Parses an iCalendar (rfc5545) formatted date and returns a DateTimeImmutable object.
- parseDateTime() : DateTimeImmutable
- Parses an iCalendar (rfc5545) formatted datetime and returns a DateTimeImmutable object.
- parseDuration() : DateInterval|string
- Parses an iCalendar (RFC5545) formatted duration value.
- parseVCardDateAndOrTime() : array<string|int, mixed>
- This method parses a vCard date and or time value.
- parseVCardDateTime() : array<string|int, mixed>
- This method parses a vCard date and or time value.
- parseVCardTime() : array<string|int, mixed>
- This method parses a vCard TIME value.
Methods
parse()
Parses either a Date or DateTime, or Duration value.
public
static parse(string $date[, DateTimeZone|string $referenceTz = null ]) : DateTimeImmutable|DateInterval
Parameters
- $date : string
- $referenceTz : DateTimeZone|string = null
Return values
DateTimeImmutable|DateInterval —parseDate()
Parses an iCalendar (rfc5545) formatted date and returns a DateTimeImmutable object.
public
static parseDate(string $date[, DateTimeZone $tz = null ]) : DateTimeImmutable
Parameters
- $date : string
- $tz : DateTimeZone = null
Return values
DateTimeImmutable —parseDateTime()
Parses an iCalendar (rfc5545) formatted datetime and returns a DateTimeImmutable object.
public
static parseDateTime(string $dt[, DateTimeZone $tz = null ]) : DateTimeImmutable
Specifying a reference timezone is optional. It will only be used if the non-UTC format is used. The argument is used as a reference, the returned DateTimeImmutable object will still be in the UTC timezone.
Parameters
- $dt : string
- $tz : DateTimeZone = null
Return values
DateTimeImmutable —parseDuration()
Parses an iCalendar (RFC5545) formatted duration value.
public
static parseDuration(string $duration[, bool $asString = false ]) : DateInterval|string
This method will either return a DateTimeInterval object, or a string suitable for strtotime or DateTime::modify.
Parameters
- $duration : string
- $asString : bool = false
Return values
DateInterval|string —parseVCardDateAndOrTime()
This method parses a vCard date and or time value.
public
static parseVCardDateAndOrTime(string $date) : array<string|int, mixed>
This can be used for the DATE, DATE-TIME and DATE-AND-OR-TIME value.
This method returns an array, not a DateTime value. The elements in the array are in the following order: year, month, date, hour, minute, second, timezone Almost any part of the string may be omitted. It's for example legal to just specify seconds, leave out the year, etc.
Timezone is either returned as 'Z' or as '+0800'
For any non-specified values null is returned.
List of date formats that are supported: 20150128 2015-01 --01 --0128 ---28
List of supported time formats: 13 1353 135301 -53 -5301 --01 (unreachable, see the tests) --01Z --01+1234
List of supported date-time formats: 20150128T13 --0128T13 ---28T13 ---28T1353 ---28T135301 ---28T13Z ---28T13+1234
See the regular expressions for all the possible patterns.
Times may be postfixed by a timezone offset. This can be either 'Z' for UTC, or a string like -0500 or +1100.
Parameters
- $date : string
Return values
array<string|int, mixed> —parseVCardDateTime()
This method parses a vCard date and or time value.
public
static parseVCardDateTime(string $date) : array<string|int, mixed>
This can be used for the DATE, DATE-TIME, TIMESTAMP and DATE-AND-OR-TIME value.
This method returns an array, not a DateTime value.
The elements in the array are in the following order: year, month, date, hour, minute, second, timezone
Almost any part of the string may be omitted. It's for example legal to just specify seconds, leave out the year, etc.
Timezone is either returned as 'Z' or as '+0800'
For any non-specified values null is returned.
List of date formats that are supported: YYYY YYYY-MM YYYYMMDD --MMDD ---DD
YYYY-MM-DD --MM-DD ---DD
List of supported time formats:
HH HHMM HHMMSS -MMSS --SS
HH HH:MM HH:MM:SS -MM:SS --SS
A full basic-format date-time string looks like : 20130603T133901
A full extended-format date-time string looks like : 2013-06-03T13:39:01
Times may be postfixed by a timezone offset. This can be either 'Z' for UTC, or a string like -0500 or +1100.
Parameters
- $date : string
Return values
array<string|int, mixed> —parseVCardTime()
This method parses a vCard TIME value.
public
static parseVCardTime(string $date) : array<string|int, mixed>
This method returns an array, not a DateTime value.
The elements in the array are in the following order: hour, minute, second, timezone
Almost any part of the string may be omitted. It's for example legal to just specify seconds, leave out the hour etc.
Timezone is either returned as 'Z' or as '+08:00'
For any non-specified values null is returned.
List of supported time formats:
HH HHMM HHMMSS -MMSS --SS
HH HH:MM HH:MM:SS -MM:SS --SS
A full basic-format time string looks like : 133901
A full extended-format time string looks like : 13:39:01
Times may be postfixed by a timezone offset. This can be either 'Z' for UTC, or a string like -0500 or +11:00.
Parameters
- $date : string