class DateHelper (View source)

Defines Gregorian Calendar date values.

Lots of helpful functions for use in massaging dates, specific to the Gregorian calendar system. The values include both translated and untranslated values.

Untranslated values are useful as array keys and as css identifiers, and should be listed in English.

Translated values are useful for display to the user. All values that need translation should be hard-coded and wrapped in t() so the translation system will be able to process them.

Methods

static array
monthNamesUntranslated()

Constructs an untranslated array of month names.

static array
monthNamesAbbrUntranslated()

Constructs an untranslated array of abbreviated month names.

static array
monthNames(bool $required = FALSE)

Returns a translated array of month names.

static array
monthNamesAbbr(bool $required = FALSE)

Constructs a translated array of month name abbreviations

static array
weekDaysUntranslated()

Constructs an untranslated array of week days.

static array
weekDays(bool $required = FALSE)

Returns a translated array of week names.

static array
weekDaysAbbr(bool $required = FALSE)

Constructs a translated array of week day abbreviations.

static array
weekDaysAbbr2(bool $required = FALSE)

Constructs a translated array of 2-letter week day abbreviations.

static array
weekDaysAbbr1(bool $required = FALSE)

Constructs a translated array of 1-letter week day abbreviations.

static array
weekDaysOrdered(array $weekdays)

Reorders weekdays to match the first day of the week.

static array
years(int $min = 0, int $max = 0, bool $required = FALSE)

Constructs an array of years in a specified range.

static array
days(bool $required = FALSE, int $month = NULL, int $year = NULL)

Constructs an array of days in a month.

static array
hours(string $format = 'H', bool $required = FALSE)

Constructs an array of hours.

static array
minutes(string $format = 'i', bool $required = FALSE, int $increment = 1)

Constructs an array of minutes.

static array
seconds(string $format = 's', bool $required = FALSE, int $increment = 1)

Constructs an array of seconds.

static array
ampm(bool $required = FALSE)

Constructs an array of AM and PM options.

static int
daysInMonth(mixed $date = NULL)

Identifies the number of days in a month for a date.

static int
daysInYear(mixed $date = NULL)

Identifies the number of days in a year for a date.

static int
dayOfWeek(mixed $date = NULL)

Returns day of week for a given date (0 = Sunday).

static string
dayOfWeekName(mixed $date = NULL, string $abbr = TRUE)

Returns translated name of the day of week for a given date.

Details

static array monthNamesUntranslated()

Constructs an untranslated array of month names.

Return Value

array

An array of month names.

static array monthNamesAbbrUntranslated()

Constructs an untranslated array of abbreviated month names.

Return Value

array

An array of month names.

static array monthNames(bool $required = FALSE)

Returns a translated array of month names.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of month names.

static array monthNamesAbbr(bool $required = FALSE)

Constructs a translated array of month name abbreviations

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of month abbreviations.

static array weekDaysUntranslated()

Constructs an untranslated array of week days.

Return Value

array

An array of week day names

static array weekDays(bool $required = FALSE)

Returns a translated array of week names.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of week day names

static array weekDaysAbbr(bool $required = FALSE)

Constructs a translated array of week day abbreviations.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of week day abbreviations

static array weekDaysAbbr2(bool $required = FALSE)

Constructs a translated array of 2-letter week day abbreviations.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of week day 2 letter abbreviations

static array weekDaysAbbr1(bool $required = FALSE)

Constructs a translated array of 1-letter week day abbreviations.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of week day 1 letter abbreviations

static array weekDaysOrdered(array $weekdays)

Reorders weekdays to match the first day of the week.

Parameters

array $weekdays

An array of weekdays.

Return Value

array

An array of weekdays reordered to match the first day of the week. The keys will remain unchanged. For example, if the first day of the week is set to be Monday, the array keys will be [1, 2, 3, 4, 5, 6, 0].

static array years(int $min = 0, int $max = 0, bool $required = FALSE)

Constructs an array of years in a specified range.

Parameters

int $min

(optional) The minimum year in the array. Defaults to zero.

int $max

(optional) The maximum year in the array. Defaults to zero.

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of years in the selected range.

static array days(bool $required = FALSE, int $month = NULL, int $year = NULL)

Constructs an array of days in a month.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

int $month

(optional) The month in which to find the number of days. Defaults to NULL.

int $year

(optional) The year in which to find the number of days. Defaults to NULL.

Return Value

array

An array of days for the selected month.

static array hours(string $format = 'H', bool $required = FALSE)

Constructs an array of hours.

Parameters

string $format

(optional) A date format string that indicates the format to use for the hours. Defaults to 'H'.

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of hours in the selected format.

static array minutes(string $format = 'i', bool $required = FALSE, int $increment = 1)

Constructs an array of minutes.

Parameters

string $format

(optional) A date format string that indicates the format to use for the minutes. Defaults to 'i'.

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

int $increment

An integer value to increment the values. Defaults to 1.

Return Value

array

An array of minutes in the selected format.

static array seconds(string $format = 's', bool $required = FALSE, int $increment = 1)

Constructs an array of seconds.

Parameters

string $format

(optional) A date format string that indicates the format to use for the seconds. Defaults to 's'.

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

int $increment

An integer value to increment the values. Defaults to 1.

Return Value

array

An array of seconds in the selected format.

static array ampm(bool $required = FALSE)

Constructs an array of AM and PM options.

Parameters

bool $required

(optional) If FALSE, the returned array will include a blank value. Defaults to FALSE.

Return Value

array

An array of AM and PM options.

static int daysInMonth(mixed $date = NULL)

Identifies the number of days in a month for a date.

Parameters

mixed $date

(optional) A DrupalDateTime object or a date string. Defaults to NULL, which means to use the current date.

Return Value

int

The number of days in the month.

static int daysInYear(mixed $date = NULL)

Identifies the number of days in a year for a date.

Parameters

mixed $date

(optional) A DrupalDateTime object or a date string. Defaults to NULL, which means to use the current date.

Return Value

int

The number of days in the year.

static int dayOfWeek(mixed $date = NULL)

Returns day of week for a given date (0 = Sunday).

Parameters

mixed $date

(optional) A DrupalDateTime object or a date string. Defaults to NULL, which means use the current date.

Return Value

int

The number of the day in the week.

static string dayOfWeekName(mixed $date = NULL, string $abbr = TRUE)

Returns translated name of the day of week for a given date.

Parameters

mixed $date

(optional) A DrupalDateTime object or a date string. Defaults to NULL, which means use the current date.

string $abbr

(optional) Whether to return the abbreviated name for that day. Defaults to TRUE.

Return Value

string

The name of the day in the week for that date.