\cge_date_utils

A set of convenience methods to work with dates and times

Summary

Methods
Properties
Constants
date_from_form()
str_to_timestamp()
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
__construct()
No private properties found
N/A

Methods

date_from_form()

date_from_form(array $params, string $prefix, string $prefix2) : int

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

int —

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

str_to_timestamp()

str_to_timestamp(string $str) : int

Convert a string to a timestamp.

An alias for strtotime

Parameters

string $str

The input date/time string

Returns

int —

The unix timestamp

ts_set_time()

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

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

Parameters

int $timestamp
int $hour
int $minutes

Returns

int

ts_set_time_from_str()

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

Create a unix timestamp from a string.

adjust the unix timestamp accordingly.

Parameters

int $timestamp
string $str

Returns

int

is_leapyear()

is_leapyear(int $year) : bool

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

Parameters

int $year

Optional year.

Returns

bool

days_in_month()

days_in_month(int $month, int $year) : int

Return the days in the given month/year

Parameters

int $month

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

int $year

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

Returns

int

date_at()

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

Create a cge_date given specified time values

Parameters

int $month
int $day
int $year
int $hour
int $minute
int $seconds

Returns

\cge_date

ts_to_dbformat()

ts_to_dbformat(int $ts) : string

Convert a timestamp to database format

Parameters

int $ts

Returns

string

from_locale_str()

from_locale_str(string $str) : int

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

Parameters

string $str

The input string

Returns

int —

The unix timestamp.

to_locale_str()

to_locale_str(int $ts, bool $time_too, string $sep) : string

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

Parameters

int $ts

The unix timestamp

bool $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( $ts)

Parameters

$ts

__construct()

__construct()