Other Functions Used By Epoch Prime

In addition to the core code that makes up Epoch Prime, several other functions have been added to improve on existing DOM functionality, as well as account for different implementations between browsers.

These functions can be used anywhere on your page; not just in Epoch Prime, as long as epochprime_classes.js is sourced to your page.

JavaScript Date Object Additions

To provide extra functionality to the JavaScript Date object and reduce overall code complexity, several functions have been added to the standard functions available.

You can access these functions in the same manner as the standard Date methods, i.e. var prettydate = mydate.dateFormat('Y-m-d');

Date::getDayOfYear()

Returns the day of the year (0 to 365/366) for this date.

Arguments

(none)

Return Values

int

Date::getWeek()

Returns the week number for this date. dowOffset is the day of week the week "starts" on for your locale - it can be from 0 to 6. If dowOffset is 1 (Monday), the week returned is the ISO week number.

Arguments

  • int dowOffset (default 0)

Return Values

int

Date::getUeDay()

Returns the number of DAYS since the UNIX Epoch – good for comparing the date portion without taking into account the time.

Arguments

(none)

Return Values

int

Date::dateFormat(format)

Formats the date in the format specified in format. If format is NOT set, it will default to the ISO 8601 date/time standard (i.e. 2006-04-05 20:52:21), or to a format set by the user. The format string components are the same as the PHP date() function, with minor exceptions.

Arguments

  • string format

Return Values

string

Usage

The format string consists of the following abbreviations:

Days
format characterDescriptionExample returned values
dDay of the month, 2 digits with leading zeros01 to 31
DA textual representation of a day, three lettersMon through Sun
jDay of the month without leading zeros1 to 31
l (lowercase 'L')A full textual representation of the day of the weekSunday through Saturday
Months
format characterDescriptionExample returned values
FA full textual representation of a month, such as January or MarchJanuary through December
mNumeric representation of a month, with leading zeros01 through 12
MA short textual representation of a month, three lettersJan through Dec
nNumeric representation of a month, without leading zeros1 through 12
Years
format characterDescriptionExample returned values
YA full numeric representation of a year, 4 digits1999 or 2003
yA two digit representation of a year99 or 03
Times
format characterDescriptionExample returned values
aLowercase Ante meridiem and Post meridiemam or pm
AUppercase Ante meridiem and Post meridiemAM or PM
g12-hour format of an hour without leading zeros1 through 12
G24-hour format of an hour without leading zeros0 through 23
h12-hour format of an hour with leading zeros01 through 12
H24-hour format of an hour with leading zeros00 through 23
iMinutes with leading zeros00 to 59
sSeconds, with leading zeros00 through 59

DOM-related functions

Some of these functions exist to mediate the differences of DOM implementation between different browsers, while others are added to make certain DOM-related operations easier and faster.

addEventHandler(element, type, func)

Dynamically adds an event handler function to an element – use this function instead of direct event handler assignment (i.e. obj.onclick=xxx)when possible, since it allows you to have multiple event handlers for the same element. This function is a workaround to deal with Internet Explorer's nonstandard DOM event model.

Arguments

  • HTMLElement element
  • string type
  • function func

Return Values

(none)

Usage

type can be any one of the standard DOM events (click, mousedown, submit, focus, etc).

removeEventHandler(element, type, func)

Dynamically adds an event handler function to an element – use this function instead of direct event handler assignment when possible, since it allows you to have multiple event handlers for the same element. This function is a workaround to deal with Internet Explorer's poorly-implemented DOM event model.

Arguments

  • HTMLElement element
  • string type
  • function func

Return Values

(none)

Usage

type can be any one of the standard DOM events (click, mousedown, submit, focus, etc).

function getTop(element)

Returns the absolute Top value of element, in pixels

Arguments

  • HTMLElement element

Return Values

int

function getLeft(element)

Returns the absolute Left value of element, in pixels

Arguments

  • HTMLElement element

Return Values

int