\ZDateHelper

Zap Calendar Date Helper Class

Helper class for various date functions

Summary

Methods
Properties
Constants
DayInMonth()
isToday()
isBeforeToday()
isAfterToday()
isTomorrow()
isFuture()
isPast()
now()
isWeekend()
toSqlDateTime()
toSqlDate()
fromiCaltoUnixDateTime()
fromUnixDateTimetoiCal()
iCalDurationtoSeconds()
inDay()
toUnixDate()
toUnixDateTime()
addDate()
getDateFromDay()
toLocalDateTime()
toUTCDateTime()
getAbsDate()
toiCalDateTime()
toiCalDate()
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

DayInMonth()

DayInMonth(integer  $month, integer  $year) : integer

Find the number of days in a month

Parameters

integer $month

Month is between 1 and 12 inclusive

integer $year

is between 1 and 32767 inclusive

Returns

integer

isToday()

isToday(integer  $date, integer  $tzid = "UTC") : boolean

Is given date today?

Parameters

integer $date

date in Unix timestamp format

integer $tzid

PHP recognized timezone (default is UTC)

Returns

boolean

isBeforeToday()

isBeforeToday(integer  $date, integer  $tzid = "UTC") : boolean

Is given date before today?

Parameters

integer $date

date in Unix timestamp format

integer $tzid

PHP recognized timezone (default is UTC)

Returns

boolean

isAfterToday()

isAfterToday(integer  $date, integer  $tzid = "UTC") : boolean

Is given date after today?

Parameters

integer $date

date in Unix timestamp format

integer $tzid

PHP recognized timezone (default is UTC)

Returns

boolean

isTomorrow()

isTomorrow(integer  $date, integer  $tzid = "UTC") : boolean

Is given date tomorrow?

Parameters

integer $date

date in Unix timestamp format

integer $tzid

PHP recognized timezone (default is UTC)

Returns

boolean

isFuture()

isFuture(integer  $date, integer  $tzid = "UTC") : boolean

Is given date in the future?

This routine differs from isAfterToday() in that isFuture() will return true for date-time values later in the same day.

Parameters

integer $date

date in Unix timestamp format

integer $tzid

PHP recognized timezone (default is UTC)

Returns

boolean

isPast()

isPast(integer  $date, integer  $tzid = "UTC") : boolean

Is given date in the past?

This routine differs from isBeforeToday() in that isPast() will return true for date-time values earlier in the same day.

Parameters

integer $date

date in Unix timestamp format

integer $tzid

PHP recognized timezone (default is UTC)

Returns

boolean

now()

now(string  $tzid = "UTC") : integer

Return current Unix timestamp in local timezone

Parameters

string $tzid

PHP recognized timezone

Returns

integer

isWeekend()

isWeekend(integer  $date) : boolean

Is given date fall on a weekend?

Parameters

integer $date

Unix timestamp

Returns

boolean

toSqlDateTime()

toSqlDateTime(integer  $t) : string

Format Unix timestamp to SQL date-time

Parameters

integer $t

Unix timestamp

Returns

string

toSqlDate()

toSqlDate(integer  $t) : string

Format Unix timestamp to SQL date

Parameters

integer $t

Unix timestamp

Returns

string

fromiCaltoUnixDateTime()

fromiCaltoUnixDateTime(string  $datetime) : integer

Format iCal date-time string to Unix timestamp

Parameters

string $datetime

in iCal time format ( YYYYMMDD or YYYYMMDDTHHMMSS or YYYYMMDDTHHMMSSZ )

Returns

integer —

Unix timestamp

fromUnixDateTimetoiCal()

fromUnixDateTimetoiCal(integer  $datetime) : string

Format Unix timestamp to iCal date-time string

Parameters

integer $datetime

Unix timestamp

Returns

string

iCalDurationtoSeconds()

iCalDurationtoSeconds(string  $duration) 

Convert iCal duration string to # of seconds

Parameters

string $duration

iCal duration string

return int

inDay()

inDay(integer  $daystart, integer  $begin, integer  $end) : boolean

Check if day falls within date range

Parameters

integer $daystart

start of day in Unix timestamp format

integer $begin

Unix timestamp of starting date range

integer $end

Unix timestamp of end date range

Returns

boolean

toUnixDate()

toUnixDate(string  $datetime) : integer

Convert SQL date or date-time to Unix timestamp

Parameters

string $datetime

SQL date or date-time

Returns

integer —

Unix date-time timestamp

toUnixDateTime()

toUnixDateTime(string  $datetime) : integer

Convert SQL date or date-time to Unix date timestamp

Parameters

string $datetime

SQL date or date-time

Returns

integer —

Unix timestamp

addDate()

addDate(integer  $date, integer  $hour, integer  $min, integer  $sec, integer  $month, integer  $day, integer  $year, string  $tzid = "UTC") 

Date math: add or substract from current date to get a new date

Parameters

integer $date

date to add or subtract from

integer $hour

add or subtract hours from date

integer $min

add or subtract minutes from date

integer $sec

add or subtract seconds from date

integer $month

add or subtract months from date

integer $day

add or subtract days from date

integer $year

add or subtract years from date

string $tzid

PHP recognized timezone (default is UTC)

getDateFromDay()

getDateFromDay(integer  $date, integer  $week, integer  $wday, string  $tzid = "UTC") : integer

Date math: get date from week and day in specifiec month

This routine finds actual dates for the second Tuesday of the month, last Friday of the month, etc. For second Tuesday, use $week = 1, $wday = 2 for last Friday, use $week = -1, $wday = 5

Parameters

integer $date

Unix timestamp

integer $week

week number, 0 is first week, -1 is last

integer $wday

day of week, 0 is Sunday, 6 is Saturday

string $tzid

PHP supported timezone

Returns

integer —

Unix timestamp

toLocalDateTime()

toLocalDateTime(string  $sqldate, string  $tzid = "UTC") : string

Convert UTC date-time to local date-time

Parameters

string $sqldate

SQL date-time string

string $tzid

PHP recognized timezone (default is "UTC")

Returns

string —

SQL date-time string

toUTCDateTime()

toUTCDateTime(string  $sqldate, string  $tzid = "UTC") : string

Convert local date-time to UTC date-time

Parameters

string $sqldate

SQL date-time string

string $tzid

PHP recognized timezone (default is "UTC")

Returns

string —

SQL date-time string

getAbsDate()

getAbsDate(string  $date, string  $rdate = "") : string

Convert from a relative date to an absolute date

Examples of relative dates are "-2y" for 2 years ago, "18m" for 18 months after today. Relative date uses "y", "m" and "d" for year, month and day. Relative date can be combined into comma separated list, i.e., "-1y,-1d" for 1 year and 1 day ago.

Parameters

string $date

relative date string (i.e. "1y" for 1 year from today)

string $rdate

reference date, or blank for current date (in SQL date-time format)

Returns

string —

in SQL date-time format

toiCalDateTime()

toiCalDateTime(integer  $datetime = null) : string

Format Unix timestamp to iCal date-time format

Parameters

integer $datetime

Unix timestamp

Returns

string —

iCal date-time string

toiCalDate()

toiCalDate(integer  $datetime = null) : string

Format Unix timestamp to iCal date format

Parameters

integer $datetime

Unix timestamp

Returns

string —

iCal date-time string