CoolCMS API

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
string

addToDate()

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
string

ageDuration()

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 (yearsShort when $short)
  • at least 1 month -> months (30.44-day months; monthsShort when $short)
  • otherwise -> days (daysShort when $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
string

compareDates()

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|null

formatForDateInput()

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|null

formatForDatetimeInput()

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|null

formatFromDateInput()

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|null

formatFromDatetimeInput()

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|null

getDate()

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
string

getDay()

Returns value of day in date

public static getDay(string|DateTimeInterface $date) : string
Parameters
$date : string|DateTimeInterface
Return values
string

getMonth()

Returns value of month in date

public static getMonth(string|DateTimeInterface $date) : string
Parameters
$date : string|DateTimeInterface
Return values
string

getQuarter()

Returns a quarter from a date

public static getQuarter(string|DateTimeInterface $date) : int
Parameters
$date : string|DateTimeInterface
Return values
int

getWeek()

public static getWeek(string|DateTimeInterface $date) : int
Parameters
$date : string|DateTimeInterface
Return values
int

getYear()

Returns value of year in date

public static getYear(string|DateTimeInterface $date) : string
Parameters
$date : string|DateTimeInterface
Return values
string

isBetweenDates()

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
bool

newDate()

public static newDate(int $plusDays[, string $format = "Y-m-d" ]) : string
Parameters
$plusDays : int
$format : string = "Y-m-d"
Return values
string

now()

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
string

subDays()

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
string

subFromDate()

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
string

today()

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|null

formatAt()

`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
string

toTimestamp()

Normalizes a date to a timestamp

private static toTimestamp(string|DateTimeInterface|int|null $date) : int|false
Parameters
$date : string|DateTimeInterface|int|null
Return values
int|false
On this page

Search results