DatePeriod
in package

Usage: <pre>new DatePeriod(string $period);</pre> <pre>new DatePeriod(DateTime|string $startDate, DateTime|string $endDate);</pre> where $period is a string like '2020-01-25 - 2020-02-10' (or '2020-01-25 - 2020-01-25' - even if the dates are the same).

Tags
since
1.0

Table of Contents

PERIOD_PATTERN  = '/^%start_date% - %end_date%$/'
$endDate  : DateTime
$startDate  : DateTime
__clone()  : mixed
__construct()  : mixed
See variants in the class description.
__toString()  : string
calcDays()  : int
createFromPeriod()  : static|null
inPeriod()  : bool
setEndDate()  : mixed
setStartDate()  : mixed
splitToDates()  : array<string|int, DateTime>
toString()  : string
validate()  : string|false
convertToDate()  : DateTime
parsePeriod()  : mixed

Constants

PERIOD_PATTERN

public mixed PERIOD_PATTERN = '/^%start_date% - %end_date%$/'
Tags
since
1.0

Properties

$endDate

public DateTime $endDate = null
Tags
since
1.0

$startDate

public DateTime $startDate = 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 $dateOrPeriod[, DateTime|string $endDate = null ]) : mixed
Parameters
$dateOrPeriod : DateTime|string
$endDate : 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

calcDays()

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

createFromPeriod()

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

inPeriod()

public inPeriod(DateTime|string $date) : bool
Parameters
$date : DateTime|string
Tags
since
1.0
Return values
bool

setEndDate()

public setEndDate(DateTime|string $endDate) : mixed
Parameters
$endDate : DateTime|string
Tags
since
1.0
Return values
mixed

setStartDate()

public setStartDate(DateTime|string $startDate) : mixed
Parameters
$startDate : DateTime|string
Tags
since
1.0
Return values
mixed

splitToDates()

public splitToDates() : array<string|int, DateTime>
Tags
since
1.2.2
Return values
array<string|int, DateTime>

['Y-m-d' => DateTime]

toString()

public toString([mixed $format = 'public' ][, mixed $glue = ' - ' ]) : string
Parameters
$format : mixed = 'public'
$glue : mixed = ' - '
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.

convertToDate()

protected convertToDate(DateTime|string $input) : DateTime
Parameters
$input : DateTime|string
Tags
since
1.0
Return values
DateTime

parsePeriod()

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

Search results