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
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
Properties
$endDate
public
DateTime
$endDate
= null
Tags
$startDate
public
DateTime
$startDate
= null
Tags
Methods
__clone()
public
__clone() : mixed
Tags
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
Return values
mixed —__toString()
public
__toString() : string
Tags
Return values
string —calcDays()
public
calcDays() : int
Tags
Return values
int —createFromPeriod()
public
static createFromPeriod(string $period) : static|null
Parameters
- $period : string
Tags
Return values
static|null —inPeriod()
public
inPeriod(DateTime|string $date) : bool
Parameters
- $date : DateTime|string
Tags
Return values
bool —setEndDate()
public
setEndDate(DateTime|string $endDate) : mixed
Parameters
- $endDate : DateTime|string
Tags
Return values
mixed —setStartDate()
public
setStartDate(DateTime|string $startDate) : mixed
Parameters
- $startDate : DateTime|string
Tags
Return values
mixed —splitToDates()
public
splitToDates() : array<string|int, DateTime>
Tags
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
Return values
string —validate()
public
static validate(string $period) : string|false
Parameters
- $period : string
Tags
Return values
string|false —Valid string or false.
convertToDate()
protected
convertToDate(DateTime|string $input) : DateTime
Parameters
- $input : DateTime|string
Tags
Return values
DateTime —parsePeriod()
protected
parsePeriod(string $period) : mixed
Parameters
- $period : string