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
since
1.0

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
since
1.0

Properties

$endTime

public DateTime $endTime = null
Tags
since
1.0

$startTime

public DateTime $startTime = null
Tags
since
1.0

Methods

__clone()

public __clone() : mixed
Tags
since
1.0
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
since
1.0
Return values
mixed

__toString()

public __toString() : string
Tags
since
1.0
Return values
string

createFromPeriod()

public static createFromPeriod(string $period) : static|null
Parameters
$period : string
Tags
since
1.0
Return values
static|null

diffPeriod()

public diffPeriod(self $period) : mixed
Parameters
$period : self
Tags
since
1.2.1
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
since
1.0
Return values
mixed

getDuration()

public getDuration() : int
Tags
since
1.0
Return values
int

Duration time in minutes.

getEndTime()

public getEndTime() : DateTime
Tags
since
1.13.0
Return values
DateTime

getStartTime()

public getStartTime() : DateTime
Tags
since
1.13.0
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
since
1.2.1
since
1.13.0

added the $compare argument.

Return values
bool

isEmpty()

public isEmpty() : bool
Tags
since
1.2.1
Return values
bool

isInPeriod()

public isInPeriod(DateTime $date) : bool
Parameters
$date : DateTime
Tags
since
1.13.0
Return values
bool

isSubperiodOf()

public isSubperiodOf(self $period) : bool
Parameters
$period : self
Tags
since
1.2.1
Return values
bool

mergePeriod()

public mergePeriod(self $period) : mixed
Parameters
$period : self
Tags
since
1.2
Return values
mixed

mergePeriods()

public mergePeriods(array<string|int, self> $periods) : mixed
Parameters
$periods : array<string|int, self>
Tags
since
1.2
Return values
mixed

setDate()

public setDate(DateTime $date) : mixed
Parameters
$date : DateTime
Tags
since
1.0
Return values
mixed

setEndTime()

public setEndTime(string|int $endTime) : mixed
Parameters
$endTime : string|int
Tags
since
1.0
Return values
mixed

setStartTime()

public setStartTime(DateTime|string $startTime) : mixed
Parameters
$startTime : DateTime|string
Tags
since
1.0
Return values
mixed

splitByPeriod()

public splitByPeriod(self $period) : array<string|int, self>
Parameters
$period : self
Tags
since
1.2.1
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
since
1.0
Return values
string

validate()

public static validate(string $period) : string|false
Parameters
$period : string
Tags
since
1.0
Return values
string|false

Valid string or false.

makeDateTime()

protected makeDateTime(DateTime|string $input) : DateTime
Parameters
$input : DateTime|string
Tags
since
1.2.1
Return values
DateTime

parsePeriod()

protected parsePeriod(string $period) : mixed
Parameters
$period : string
Tags
since
1.0
Return values
mixed

Search results