class DateHelper implements ProtectedContextAwareInterface (View source)

Date helpers for Eel contexts

Properties

protected DatetimeFormatter $datetimeFormatter
protected Service $localizationService

Methods

parse(string $string, string $format)

Parse a date from string with a format to a DateTime object

string
format(int|string|DateTime|DateInterval $date, string $format)

Format a date (or interval) to a string with a given format

string
formatCldr(int|string|DateTime $date, string $cldrFormat, null|string $locale = null)

Format a date to a string with a given cldr format

create(string $time)

Get a date object by given date or time format

now()

Get the current date and time

today()

Get the current date

add(DateTime $date, string|DateInterval $interval)

Add an interval to a date and return a new DateTime object

subtract(DateTime $date, string|DateInterval $interval)

Subtract an interval from a date and return a new DateTime object

diff(DateTime $dateA, DateTime $dateB)

Get the difference between two dates as a \DateInterval object

int
dayOfMonth(DateTimeInterface $dateTime)

Get the day of month of a date

int
month(DateTimeInterface $dateTime)

Get the month of a date

int
year(DateTimeInterface $dateTime)

Get the year of a date

int
hour(DateTimeInterface $dateTime)

Get the hour of a date (24 hour format)

int
minute(DateTimeInterface $dateTime)

Get the minute of a date

int
second(DateTimeInterface $dateTime)

Get the second of a date

bool
allowsCallOfMethod(string $methodName)

All methods are considered safe

Details

DateTime parse(string $string, string $format)

Parse a date from string with a format to a DateTime object

Parameters

string $string
string $format

Return Value

DateTime

string format(int|string|DateTime|DateInterval $date, string $format)

Format a date (or interval) to a string with a given format

See formatting options as in PHP date()

Parameters

int|string|DateTime|DateInterval $date
string $format

Return Value

string

string formatCldr(int|string|DateTime $date, string $cldrFormat, null|string $locale = null)

Format a date to a string with a given cldr format

Parameters

int|string|DateTime $date
string $cldrFormat

Format string in CLDR format (see http://cldr.unicode.org/translation/date-time)

null|string $locale

String locale - example (de|en|ru_RU)

Return Value

string

DateTime create(string $time)

Get a date object by given date or time format

Examples::

Date.create('2018-12-04') Date.create('first day of next year')

Parameters

string $time

A date/time string. For valid formats see http://php.net/manual/en/datetime.formats.php

Return Value

DateTime

DateTime now()

Get the current date and time

Examples::

Date.now().timestamp

Return Value

DateTime

DateTime today()

Get the current date

Return Value

DateTime

DateTime add(DateTime $date, string|DateInterval $interval)

Add an interval to a date and return a new DateTime object

Parameters

DateTime $date
string|DateInterval $interval

Return Value

DateTime

DateTime subtract(DateTime $date, string|DateInterval $interval)

Subtract an interval from a date and return a new DateTime object

Parameters

DateTime $date
string|DateInterval $interval

Return Value

DateTime

DateInterval diff(DateTime $dateA, DateTime $dateB)

Get the difference between two dates as a \DateInterval object

Parameters

DateTime $dateA
DateTime $dateB

Return Value

DateInterval

int dayOfMonth(DateTimeInterface $dateTime)

Get the day of month of a date

Parameters

DateTimeInterface $dateTime

Return Value

int

The day of month of the given date

int month(DateTimeInterface $dateTime)

Get the month of a date

Parameters

DateTimeInterface $dateTime

Return Value

int

The month of the given date

int year(DateTimeInterface $dateTime)

Get the year of a date

Parameters

DateTimeInterface $dateTime

Return Value

int

The year of the given date

int hour(DateTimeInterface $dateTime)

Get the hour of a date (24 hour format)

Parameters

DateTimeInterface $dateTime

Return Value

int

The hour of the given date

int minute(DateTimeInterface $dateTime)

Get the minute of a date

Parameters

DateTimeInterface $dateTime

Return Value

int

The minute of the given date

int second(DateTimeInterface $dateTime)

Get the second of a date

Parameters

DateTimeInterface $dateTime

Return Value

int

The second of the given date

bool allowsCallOfMethod(string $methodName)

All methods are considered safe

Parameters

string $methodName

Return Value

bool