class SAPO.Utility.TimeEvent
Abstracts a point in time and operations on it. NOTE: always fetch date component with UTC methods, otherwise you may get different results (affected by time zone).
 required SAPO.Utility.I18n in which case one needs to load previously to this class /SAPO/Utility/TimeEvent/0.1/lang.js
 
Authors:
jose.p.dias AT co.sapo.pt
Version:
0.1
Since:
February 2011
Defined in Utility/TimeEvent/0.1/lib.js

Property Summary
timestamp length of a day (in ms)
timestamp length of an hour (in ms)
timestamp length of a minute (in ms)
timestamp length of a month, i.e., 365.25 days/12 (in ms)
timestamp length of a second (in ms)
timestamp length of a week (in ms)
timestamp length of a year, i.e. 365.25 days (in ms)

Constructor Summary
TimeEvent (Number|String|undefined date, [String label], [Object custom])

Function Summary
TimeEvent add (TimeEvent|Number other)
otherEvt another event to this one
returns a new instance of TimeEvent
TimeEvent dateDiff (Number YY, Number MM, Number DD, [Number HH], [Number mm], [Number ss])
to shift the TimeEvent to the future(positive) or past (negative)
TimeEvent divide (TimeEvent|Number other)
devides this event by given event
String extendedDate (Boolean withTime)
returns the extended string representing a date
String format (String formatStr)
ex 1999-03-07 04:09:01
 supports:
  %YY year            (1999)
  %yy year            (99)

  %MM month           ('March')
  %Mm month           (03)
  %mm month           (3)         (1-12)
  %mM month           ('Mar')

  %Dd day of month    (07)
  %dd day of month    (7)         (1-31)

  %DY day of year    (037)      (001-366)
  %dy day of year    (37)         (1-366)

  %WW day of week     ('Terça')
  %ww day of week     (2)         (0-6)
  %wW day of week     ('Ter')

  %w  week of year    (...)

  %H  hours           (04)
  %h  hours           (4)         (0-23)

  %M  minutes         (09)
  %m  minutes         (9)         (0-59)

  %S  seconds         (01)
  %s  seconds         (1)         (0-59)
 
number of hours of difference between local time and UTC time (in Portugal differs 1-0 hours, depending on DST)
returns timestamp in local time
TimeEvent multiply (TimeEvent|Number other)
multiplies another event with this one
returns next relevant ts
sets HH:mm:ss of the day to 00:00:00
sets timeEvent to beginning of the month
sets timeEvent to beginning of the year
sets timeEvent to today at 00:00
String shortenedExtendedDate (Boolean withTime, Boolean withYear)
returns the shortened extended string representing a date TODO: english case 'Sun, Mar 4th'
user to sort lists of TimeEvents chronologically
TimeEvent subtract (TimeEvent|Number other)
subtracts another event from this one
returns time diff string
returns time part of the dateS TODO: validate
returns string representation of relevant internal state (for human inspection)
TimeEvent tsDiff (Number deltaTs)
to shift the TimeEvent to the future(positive) or past (negative) DEPRECATED - use add/subtract
updateTs (Number ts)
to alter the event to specified timestamp
Number weekNumber()
returns the nth week number of the year

Property Details

property dayTs

timestamp length of a day (in ms)

property hourTs

timestamp length of an hour (in ms)

property minuteTs

timestamp length of a minute (in ms)

property monthTs

timestamp length of a month, i.e., 365.25 days/12 (in ms)

property secondTs

timestamp length of a second (in ms)

property weekTs

timestamp length of a week (in ms)

property yearTs

timestamp length of a year, i.e. 365.25 days (in ms)

Constructor Details

constructor TimeEvent

TimeEvent(Number|String|undefined date, [String label], [Object custom])
Parameters:
date - string in the format "YYYY-MM-DD", valid UNIX timestamp or JavaScript Date
[label] - short text description
[custom] - optional custom object for holding additional data

Function Details

function add

TimeEvent add(TimeEvent|Number other)
otherEvt another event to this one
Parameters:
other

function clone

TimeEvent clone()
returns a new instance of TimeEvent
Returns:
new instance

function dateDiff

TimeEvent dateDiff(Number YY, Number MM, Number DD, [Number HH], [Number mm], [Number ss])
to shift the TimeEvent to the future(positive) or past (negative)
Parameters:
YY - number of years of difference to apply
MM - number of months of difference to apply
DD - number of days of difference to apply
[HH] - number of hours of difference to apply
[mm] - number of minutes of difference to apply
[ss] - number of seconds of difference to apply

function divide

TimeEvent divide(TimeEvent|Number other)
devides this event by given event
Parameters:
other TODO: check if used

function extendedDate

String extendedDate(Boolean withTime)
returns the extended string representing a date
Parameters:
withTime

function format

String format(String formatStr)
ex 1999-03-07 04:09:01
 supports:
  %YY year            (1999)
  %yy year            (99)

  %MM month           ('March')
  %Mm month           (03)
  %mm month           (3)         (1-12)
  %mM month           ('Mar')

  %Dd day of month    (07)
  %dd day of month    (7)         (1-31)

  %DY day of year    (037)      (001-366)
  %dy day of year    (37)         (1-366)

  %WW day of week     ('Terça')
  %ww day of week     (2)         (0-6)
  %wW day of week     ('Ter')

  %w  week of year    (...)

  %H  hours           (04)
  %h  hours           (4)         (0-23)

  %M  minutes         (09)
  %m  minutes         (9)         (0-59)

  %S  seconds         (01)
  %s  seconds         (1)         (0-59)
 
Parameters:
formatStr

function getLocalHoursDiffFromUTC

Number getLocalHoursDiffFromUTC()
number of hours of difference between local time and UTC time (in Portugal differs 1-0 hours, depending on DST)

function getLocalTimestamp

Number getLocalTimestamp()
returns timestamp in local time

function multiply

TimeEvent multiply(TimeEvent|Number other)
multiplies another event with this one
Parameters:
other TODO: check if used, check

function nextMajorTs

TimeEvent nextMajorTs(String unit)
returns next relevant ts
Parameters:
unit - one of 'Y', 'M', 'D', 'H', 'm', 's'
Returns:
next major timestamp

function setStartOfDay

TimeEvent setStartOfDay()
sets HH:mm:ss of the day to 00:00:00

function setStartOfMonth

TimeEvent setStartOfMonth()
sets timeEvent to beginning of the month

function setStartOfYear

TimeEvent setStartOfYear()
sets timeEvent to beginning of the year

function setToday

TimeEvent setToday()
sets timeEvent to today at 00:00

function shortenedExtendedDate

String shortenedExtendedDate(Boolean withTime, Boolean withYear)
returns the shortened extended string representing a date TODO: english case 'Sun, Mar 4th'
Parameters:
withTime
withYear

function sortFn

sortFn(TimeEvent a, TimeEvent b)
user to sort lists of TimeEvents chronologically
Parameters:
a
b
Returns:
{Number}

function subtract

TimeEvent subtract(TimeEvent|Number other)
subtracts another event from this one
Parameters:
other

function tellDeltaTime

String tellDeltaTime()
returns time diff string

function timePart

String timePart()
returns time part of the dateS TODO: validate

function toString

toString()
returns string representation of relevant internal state (for human inspection)
Returns:
{String}

function tsDiff

TimeEvent tsDiff(Number deltaTs)
to shift the TimeEvent to the future(positive) or past (negative) DEPRECATED - use add/subtract
Parameters:
deltaTs - timestamp delta to apply (in ms)

function updateTs

updateTs(Number ts)
to alter the event to specified timestamp
Parameters:
ts - UNIX timestamp, i.e. ms since 1970

function weekNumber

Number weekNumber()
returns the nth week number of the year