TimePeriod
in package
Usage: <pre>new TimePeriod(string $period);</pre> <pre>new TimePeriod(DateTime|string $startTime, DateTime|string $endTime);</pre> where $period is a string like '08:00 - 14:00'.
Tags
Table of Contents
- PERIOD_PATTERN = '/^%start_time% - %end_time%$/'
- $endTime : DateTime
- $startTime : DateTime
- __clone() : mixed
- __construct() : mixed
- See variants in the class description.
- __toString() : string
- createFromPeriod() : static|null
- diffPeriod() : mixed
- expand() : mixed
- getDuration() : int
- getEndTime() : DateTime
- getStartTime() : DateTime
- intersectsWith() : bool
- isEmpty() : bool
- isInPeriod() : bool
- isSubperiodOf() : bool
- mergePeriod() : mixed
- mergePeriods() : mixed
- setDate() : mixed
- setEndTime() : mixed
- setStartTime() : mixed
- splitByPeriod() : array<string|int, self>
- toString() : string
- validate() : string|false
- makeDateTime() : DateTime
- parsePeriod() : mixed
Constants
PERIOD_PATTERN
public
mixed
PERIOD_PATTERN
= '/^%start_time% - %end_time%$/'
Tags
Properties
$endTime
public
DateTime
$endTime
= null
Tags
$startTime
public
DateTime
$startTime
= null
Tags
Methods
__clone()
public
__clone() : mixed
Tags
Return values
mixed —__construct()
See variants in the class description.
public
__construct(DateTime|string $timeOrPeriod[, DateTime|string $endTime = null ]) : mixed
Parameters
- $timeOrPeriod : DateTime|string
- $endTime : DateTime|string = null
-
Optional. Null by default.
Tags
Return values
mixed —__toString()
public
__toString() : string
Tags
Return values
string —createFromPeriod()
public
static createFromPeriod(string $period) : static|null
Parameters
- $period : string
Tags
Return values
static|null —diffPeriod()
public
diffPeriod(self $period) : mixed
Parameters
- $period : self
Tags
Return values
mixed —expand()
public
expand(int $startOffset, int $endOffset) : mixed
Parameters
- $startOffset : int
-
Minutes offset for start time.
- $endOffset : int
-
Minutes offset for end time.
Tags
Return values
mixed —getDuration()
public
getDuration() : int
Tags
Return values
int —Duration time in minutes.
getEndTime()
public
getEndTime() : DateTime
Tags
Return values
DateTime —getStartTime()
public
getStartTime() : DateTime
Tags
Return values
DateTime —intersectsWith()
public
intersectsWith(self $period[, string $compare = 'datetime' ]) : bool
Parameters
- $period : self
- $compare : string = 'datetime'
-
'datetime'|'time' Optional. 'datetime' by default.
Tags
Return values
bool —isEmpty()
public
isEmpty() : bool
Tags
Return values
bool —isInPeriod()
public
isInPeriod(DateTime $date) : bool
Parameters
- $date : DateTime
Tags
Return values
bool —isSubperiodOf()
public
isSubperiodOf(self $period) : bool
Parameters
- $period : self
Tags
Return values
bool —mergePeriod()
public
mergePeriod(self $period) : mixed
Parameters
- $period : self
Tags
Return values
mixed —mergePeriods()
public
mergePeriods(array<string|int, self> $periods) : mixed
Parameters
- $periods : array<string|int, self>
Tags
Return values
mixed —setDate()
public
setDate(DateTime $date) : mixed
Parameters
- $date : DateTime
Tags
Return values
mixed —setEndTime()
public
setEndTime(string|int $endTime) : mixed
Parameters
- $endTime : string|int
Tags
Return values
mixed —setStartTime()
public
setStartTime(DateTime|string $startTime) : mixed
Parameters
- $startTime : DateTime|string
Tags
Return values
mixed —splitByPeriod()
public
splitByPeriod(self $period) : array<string|int, self>
Parameters
- $period : self
Tags
Return values
array<string|int, self> —toString()
public
toString([string $format = 'public' ][, string $glue = ' - ' ]) : string
Parameters
- $format : string = 'public'
-
Optional. 'public', 'short', 'internal' or custom time format. 'public' by default.
- $glue : string = ' - '
-
Optional. ' - ' by default.
Tags
Return values
string —validate()
public
static validate(string $period) : string|false
Parameters
- $period : string
Tags
Return values
string|false —Valid string or false.
makeDateTime()
protected
makeDateTime(DateTime|string $input) : DateTime
Parameters
- $input : DateTime|string
Tags
Return values
DateTime —parsePeriod()
protected
parsePeriod(string $period) : mixed
Parameters
- $period : string