\cge_date_utils

A set of convenience methods to work with dates and times

Summary

Methods
Properties
Constants
date_from_form()
ts_set_time()
ts_set_time_from_str()
is_leapyear()
days_in_month()
date_at()
ts_to_dbformat()
from_locale_str()
to_locale_str()
rfc_date()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

date_from_form()

date_from_form(array  $params, string  $prefix, string  $prefix2 = null) : integer

Given month, day year input fields in parameters, and a prefix create a unix timestamp this is useful when processing form data from {html_select_date}

i.e: $ts = \cge_date_utils::date_from_form($params,$id,'startdate');

Parameters

array $params

An associative array, usually from form submission.

string $prefix

The prefix for the Month, Day, and Year fields within the params array

string $prefix2

An optional second prefix to append to the first one (i.e: the field name)

Returns

integer —

unix timestamp representing the date in the input parmeters at 00:00 hours. or null

ts_set_time()

ts_set_time(integer  $timestamp, integer  $hour, integer  $minutes) : integer

Given a unxix timestamp, an hour and minutes value adjust the unix timestamp accordingly.

Parameters

integer $timestamp
integer $hour
integer $minutes

Returns

integer

ts_set_time_from_str()

ts_set_time_from_str(integer  $timestamp, string  $str) : integer

Create a unix timestamp from a string.

adjust the unix timestamp accordingly.

Parameters

integer $timestamp
string $str

Returns

integer

is_leapyear()

is_leapyear(integer  $year = null) : boolean

Test if the given year (or the current year) is a leapyear

Parameters

integer $year

Optional year.

Returns

boolean

days_in_month()

days_in_month(integer  $month = null, integer  $year = null) : integer

Return the days in the given month/year

Parameters

integer $month

The specified month, if not specified the current month is used.

integer $year

The specified year. If not specified, the current year is used.

Returns

integer

date_at()

date_at(integer  $month, integer  $day, integer  $year, integer  $hour, integer  $minute, integer  $seconds) : \cge_date

Create a cge_date given specified time values

Parameters

integer $month
integer $day
integer $year
integer $hour
integer $minute
integer $seconds

Returns

\cge_date

ts_to_dbformat()

ts_to_dbformat(integer  $ts) : string

Convert a timestamp to database format

Parameters

integer $ts

Returns

string

from_locale_str()

from_locale_str(string  $str) : integer

Convert a locale specific date/time string to a unix timestamp

Parameters

string $str

The input string

Returns

integer —

The unix timestamp.

to_locale_str()

to_locale_str(integer  $ts, boolean  $time_too = TRUE, string  $sep = '/') : string

Convert a unix timestamp to a locale specific format (currently only support US and non US).

Parameters

integer $ts

The unix timestamp

boolean $time_too

Wether or not to include time in the output string

string $sep

The separator between fields. Default is '/'

Returns

string

rfc_date()

rfc_date(integer  $ts) : string

Convert a unix timestamp to an RFC date

Parameters

integer $ts

The unix timestamp

Returns

string