class DateFunction

This class provides some date functions for the expression parser.

Properties

static mixed|null $dateFormat
static mixed|null $timezone

Methods

static DateTime
nthDayOfMonth(int $nth, int $day, int $month, int $year)

Returns the date corresponding of the nth day of a month

static int
lastDay(int $month, int $year)

Returns the last day of the month

static DateTime
firstDayOfMonth(DateTime $dateObj)

Returns a new date corresponding to the first day of the month of the given date.

static DateTime
lastDayOfMonth(DateTime $dateObj)

Returns a new date corresponding to the last day of the month of the given date.

static DateTime
addMonths(int $months, DateTime $dateObject)

Returns a new date from the input date by adding the given number of months

static DateTime|null
parseDate(string $format, string $dateStr)

Parses a date string to the given format and converts it to a DateTime object

static bool
hasFormat(string $format, string $dateStr)

Checks if a date string match a given format

static mixed
makeDate(mixed $value)

function makeDate

static bool
isDate(mixed $dateStr)

function isDate

static mixed
getMonthNames(mixed $locale = null)

function getMonthNames

static void
init()

function init

Details

at line 70
static DateTime nthDayOfMonth(int $nth, int $day, int $month, int $year)

Returns the date corresponding of the nth day of a month

Ex: nthDayOfMonth(1, 0, 1, 2017) for the question: what is the first sunday of January 2017

Parameters

int $nth The ordinal number
int $day The day of the week (0 to 6)
int $month The numeric representation of a month (1 to 12)
int $year The year

Return Value

DateTime

at line 89
static int lastDay(int $month, int $year)

Returns the last day of the month

Ex: lastDay(2, 2017) returns 28.

Parameters

int $month The numeric representation of the month (1 to 12)
int $year The year

Return Value

int

at line 104
static DateTime firstDayOfMonth(DateTime $dateObj)

Returns a new date corresponding to the first day of the month of the given date.

Parameters

DateTime $dateObj The reference date

Return Value

DateTime The new date

at line 119
static DateTime lastDayOfMonth(DateTime $dateObj)

Returns a new date corresponding to the last day of the month of the given date.

Parameters

DateTime $dateObj The reference date

Return Value

DateTime The new date

at line 135
static DateTime addMonths(int $months, DateTime $dateObject)

Returns a new date from the input date by adding the given number of months

Parameters

int $months The number of months to add
DateTime $dateObject The date to which a number of months has to be added.

Return Value

DateTime The new date

at line 158
static DateTime|null parseDate(string $format, string $dateStr)

Parses a date string to the given format and converts it to a DateTime object

Parameters

string $format The given format
string $dateStr The date to be converted

Return Value

DateTime|null The DateTime object

Exceptions

Exception

at line 181
static bool hasFormat(string $format, string $dateStr)

Checks if a date string match a given format

Parameters

string $format The given format
string $dateStr The date to be checked

Return Value

bool true if the date string has the given format, false if not

Exceptions

Exception

at line 203
static mixed makeDate(mixed $value)

function makeDate

Parameters

mixed $value

Return Value

mixed

Exceptions

Exception

at line 224
static bool isDate(mixed $dateStr)

function isDate

determines if date is true

Parameters

mixed $dateStr

Return Value

bool the value of date

at line 240
static mixed getMonthNames(mixed $locale = null)

function getMonthNames

get the value of monthNames

Parameters

mixed $locale (default: null)

Return Value

mixed the value of monthNames

at line 266
static protected void init()

function init

Return Value

void