Date
in package
Table of Contents
Methods
- addDays() : string
- Adds days to a date
- addToDate() : string
- ageDuration() : string
- Returns the age of a date as a human-readable duration (past or future alike).
- compareDates() : int
- Compares two dates
- format() : string|null
- formatForDateInput() : string|null
- formatForDatetimeInput() : string|null
- formatFromDateInput() : string|null
- formatFromDatetimeInput() : string|null
- getDate() : string
- Returns value of date in required format
- getDay() : string
- Returns value of day in date
- getMonth() : string
- Returns value of month in date
- getQuarter() : int
- Returns a quarter from a date
- getWeek() : int
- getYear() : string
- Returns value of year in date
- isBetweenDates() : bool
- newDate() : string
- now() : string
- Returns today datetime in required format
- registrateTemplateHelper() : void
- relativeDate() : string
- subDays() : string
- Subtracts days from a date
- subFromDate() : string
- today() : string
- Returns today date in required format
- validateDate() : string|null
- formatAt() : string
- `date()` over a time that may be false (an invalid or empty date from `strtotime()` or `toTimestamp()`). The file has no strict_types, so `date($f, false)` silently gave 1 Jan 1970; this does it explicitly with the same result.
- toTimestamp() : int|false
- Normalizes a date to a timestamp
Methods
addDays()
Adds days to a date
public
static addDays(string|DateTimeInterface $date, int $days[, string $format = "Y-m-d H:i:s" ]) : string
Parameters
- $date : string|DateTimeInterface
- $days : int
- $format : string = "Y-m-d H:i:s"
Return values
stringaddToDate()
public
static addToDate(string|DateTimeInterface $date, int $number[, string $interval = 'days' ][, string $format = "Y-m-d H:i:s" ]) : string
Parameters
- $date : string|DateTimeInterface
- $number : int
- $interval : string = 'days'
- $format : string = "Y-m-d H:i:s"
Return values
stringageDuration()
Returns the age of a date as a human-readable duration (past or future alike).
public
static ageDuration(string|DateTimeInterface $date[, bool $short = false ][, callable|null $translator = null ]) : string
Rules, by whole days of difference:
- 0 days -> "today"
- at least 1 year -> years (
yearsShortwhen$short) - at least 1 month -> months (30.44-day months;
monthsShortwhen$short) - otherwise -> days (
daysShortwhen$short, at least 1)
Texts come from front.general.templates.dates.ageDuration.* via $translator; without a
translation a built-in Czech fallback is used. Returns an empty string for an unparsable date.
Parameters
- $date : string|DateTimeInterface
- $short : bool = false
- $translator : callable|null = null
Return values
stringcompareDates()
Compares two dates
public
static compareDates(string|DateTimeInterface $firstDate, string|DateTimeInterface $secondDate) : int
Parameters
- $firstDate : string|DateTimeInterface
- $secondDate : string|DateTimeInterface
Return values
int —[0] - is equal [1] - first date is bigger than second [2] - first date is smaller than second
format()
public
static format([null|string|DateTimeInterface $date = null ][, string $format = "%Y-%m-%dT%H:%M:%S" ]) : string|null
Parameters
- $date : null|string|DateTimeInterface = null
- $format : string = "%Y-%m-%dT%H:%M:%S"
Return values
string|nullformatForDateInput()
public
static formatForDateInput([null|string|DateTimeInterface $date = null ][, string $format = "Y-m-d" ]) : string|null
Parameters
- $date : null|string|DateTimeInterface = null
- $format : string = "Y-m-d"
Return values
string|nullformatForDatetimeInput()
public
static formatForDatetimeInput([null|string|DateTimeInterface $date = null ][, string $format = "Y-m-d\\TH:i:s" ]) : string|null
Parameters
- $date : null|string|DateTimeInterface = null
- $format : string = "Y-m-d\\TH:i:s"
Return values
string|nullformatFromDateInput()
public
static formatFromDateInput([null|string|DateTimeInterface $date = null ][, string $format = "Y-m-d" ]) : string|null
Parameters
- $date : null|string|DateTimeInterface = null
- $format : string = "Y-m-d"
Return values
string|nullformatFromDatetimeInput()
public
static formatFromDatetimeInput([null|string|DateTimeInterface $date = null ][, string $format = "Y-m-d H:i:s" ]) : string|null
Parameters
- $date : null|string|DateTimeInterface = null
- $format : string = "Y-m-d H:i:s"
Return values
string|nullgetDate()
Returns value of date in required format
public
static getDate(string|DateTimeInterface $date[, string $format = 'Y-m-d' ][, bool $textOutput = false ]) : string
Parameters
- $date : string|DateTimeInterface
- $format : string = 'Y-m-d'
- $textOutput : bool = false
Return values
stringgetDay()
Returns value of day in date
public
static getDay(string|DateTimeInterface $date) : string
Parameters
- $date : string|DateTimeInterface
Return values
stringgetMonth()
Returns value of month in date
public
static getMonth(string|DateTimeInterface $date) : string
Parameters
- $date : string|DateTimeInterface
Return values
stringgetQuarter()
Returns a quarter from a date
public
static getQuarter(string|DateTimeInterface $date) : int
Parameters
- $date : string|DateTimeInterface
Return values
intgetWeek()
public
static getWeek(string|DateTimeInterface $date) : int
Parameters
- $date : string|DateTimeInterface
Return values
intgetYear()
Returns value of year in date
public
static getYear(string|DateTimeInterface $date) : string
Parameters
- $date : string|DateTimeInterface
Return values
stringisBetweenDates()
public
static isBetweenDates(string|DateTimeInterface $date, string|DateTimeInterface $from, string|DateTimeInterface $to) : bool
Parameters
- $date : string|DateTimeInterface
- $from : string|DateTimeInterface
- $to : string|DateTimeInterface
Return values
boolnewDate()
public
static newDate(int $plusDays[, string $format = "Y-m-d" ]) : string
Parameters
- $plusDays : int
- $format : string = "Y-m-d"
Return values
stringnow()
Returns today datetime in required format
public
static now([string $format = "Y-m-d H:i:s" ]) : string
Parameters
- $format : string = "Y-m-d H:i:s"
Return values
string —date
registrateTemplateHelper()
public
static registrateTemplateHelper(Engine $template) : void
Parameters
- $template : Engine
relativeDate()
public
static relativeDate(string|DateTimeInterface $date[, string $format = 'Y-m-d' ][, callable|null $translator = null ]) : string
Parameters
- $date : string|DateTimeInterface
- $format : string = 'Y-m-d'
- $translator : callable|null = null
Return values
stringsubDays()
Subtracts days from a date
public
static subDays(string|DateTimeInterface $date, int $days[, string $format = "Y-m-d H:i:s" ]) : string
Parameters
- $date : string|DateTimeInterface
- $days : int
- $format : string = "Y-m-d H:i:s"
Return values
stringsubFromDate()
public
static subFromDate(string|DateTimeInterface $date, int $number[, string $interval = 'days' ][, string $format = "Y-m-d H:i:s" ]) : string
Parameters
- $date : string|DateTimeInterface
- $number : int
- $interval : string = 'days'
- $format : string = "Y-m-d H:i:s"
Return values
stringtoday()
Returns today date in required format
public
static today([string $format = "Y-m-d H:i:s" ]) : string
Parameters
- $format : string = "Y-m-d H:i:s"
Return values
string —date
validateDate()
public
static validateDate(string|DateTimeInterface $date[, string $outputFormat = 'Y-m-d' ]) : string|null
Parameters
- $date : string|DateTimeInterface
- $outputFormat : string = 'Y-m-d'
Return values
string|nullformatAt()
`date()` over a time that may be false (an invalid or empty date from `strtotime()` or `toTimestamp()`). The file has no strict_types, so `date($f, false)` silently gave 1 Jan 1970; this does it explicitly with the same result.
private
static formatAt(string $format, int|false $timestamp) : string
Parameters
- $format : string
- $timestamp : int|false
Return values
stringtoTimestamp()
Normalizes a date to a timestamp
private
static toTimestamp(string|DateTimeInterface|int|null $date) : int|false
Parameters
- $date : string|DateTimeInterface|int|null