Class SimpleDate

Description

Simple date class to perform basic date calculations

WARNING USING TICKS DIRECTLY IS DANGEROUS

The ticks variable here is a little problematic... daylight saving transitions tend to make it rather frought. For example, for the purposes of this system, if you want to know what 4 days after 9am 20th March is, you expect to get 9am 23rd March regardless of a timezone change from daylight saving.

For example, this might not give you what you want:

  1.  $date new SimpleDate('2005-03-20');
But this will:
  1.  $date new SimpleDate('2005-03-20');

Located in /inc/date.php (line 42)


	
			
Variable Summary
boolean $isValid
integer $ticks
string $_cache
Method Summary
SimpleDate SimpleDate (mixed $time)
void addDays (integer $d)
void addSecs (integer $s)
void addTime ( $t, mixed $d)
void addTimeParts ([integer $sec = 0], [integer $min = 0], [integer $hour = 0], [integer $day = 0], [integer $month = 0], [integer $year = 0])
void dateString ()
void dateTimeString ()
void dayRound ()
void daysBetween (SimpleDate $date)
integer dom ()
integer dow ()
string dowShortStr ()
string dowStr ()
integer doy ()
void dsDaysBetween (SimpleDate $date)
string dump ([boolean $html = 1])
void floorTime (SimpleTime $g)
string getLongDateString ()
string getLongTimeString ()
string getShortDateString ()
string getShortTimeString ()
string getStringByFormat ( $format)
void max (SimpleDate $t)
void min (SimpleDate $t)
void monthRound ()
integer moy ()
string moyShortStr ()
string moyStr ()
void partDaysBetween (SimpleDate $date)
void quarterRound ()
void setStr (mixed $s)
void setTicks (mixed $t)
void setTime (mixed $s)
void setTimeParts ([integer $sec = 0], [integer $min = 0], [integer $hour = 0], [integer $day = 0], [integer $month = 0], [integer $year = 0])
void subtract (SimpleDate $date)
void timeString ()
void weekRound ()
integer year ()
void yearRound ()
void _setTicks ( $s)
string _T_ (string $word)
Variables
boolean $isValid = 1 (line 57)

is a valid date-time

integer $ticks = '' (line 52)

date in seconds since epoch

string $_cache = array() (line 47)

cache of date in string format

Methods
Constructor SimpleDate (line 70)

construct a Date-Time object

constructor will work with $time in the following formats:

  • YYYY-MM-DD (assumes 00:00:00 for time part)
  • YYYY-MM-DD HH:MM (assumes :00 for seconds part)
  • YYYY-MM-DD HH:MM:SS
  • seconds since epoch
  • SimpleDate object

SimpleDate SimpleDate (mixed $time)
  • mixed $time: initial time to use
addDays (line 314)

add a whole number of days to the current date-time

void addDays (integer $d)
  • integer $d: days to add
addSecs (line 338)

add a whole number of seconds to the current date-time

void addSecs (integer $s)
  • integer $s: seconds to add
addTime (line 325)

add a time (i.e. a number of seconds) to the current date-time

  • SimpleTime object
  • seconds

void addTime ( $t, mixed $d)
  • mixed $d: days to add
  • $t
addTimeParts (line 539)

Add components to the current date-time

Note that this function will take account of daylight saving in unusual (but quite sensible) ways... for example, if $today is a SimpleDate object representing midday the day before daylight saving ends, then $today->addTimeParts(24*60*60) will give a different result to $today->addTimeParts(0,0,0,1). The former will be exactly 24 hours later than the original value of $today (11:00), but the latter will 1 calendar day later (12:00).

void addTimeParts (integer $sec, integer $min, integer $hour, integer $day, integer $month, integer $year)
  • integer $sec: (optional) number of seconds to add to this date-time
  • integer $min: (optional) number of minutes to add to this date-time
  • integer $hour: (optional) number of hours to add to this date-time
  • integer $day: (optional) number of days to add to this date-time
  • integer $month: (optional) number of months to add to this date-time
  • integer $year: (optional) number of years to add to this date-time
dateString (line 108)
void dateString ()
dateTimeString (line 94)
void dateTimeString ()
dayRound (line 348)

round (down) the date-time to the current day

sets the current YYY-MM-DD HH:MM:SS to YYYY-MM-DD 00:00:00

void dayRound ()
daysBetween (line 395)

returns the number of days between two dates ($this - $date)

note that it will return fractional days across daylight saving boundaries

void daysBetween (SimpleDate $date)
  • SimpleDate $date: date to subtract from this date
dom (line 601)

return the day of month

  • return: day of month (1..31)
integer dom ()
dow (line 577)

return the day of week of the current date.

  • return: day of week (0 == Sunday, 6 == Saturday)
integer dow ()
dowShortStr (line 593)

return the (short) day of week of the current date as a string (in current language)

  • return: day of week (Sun, Mon, etc)
string dowShortStr ()
dowStr (line 585)

return the day of week of the current date as a string (in current language)

  • return: day of week (Sunday, Monday, etc)
string dowStr ()
doy (line 634)

day of year (0..365)

returns 365 only in leap years

  • return: day of year (0..365)
integer doy ()
dsDaysBetween (line 403)

returns the number of days between two dates ($this - $date) accounting for daylight saving

void dsDaysBetween (SimpleDate $date)
  • SimpleDate $date: date to subtract from this date
dump (line 651)

dump the datetimestring and ticks in a readable format

  • return: datetimestring and ticks
string dump ([boolean $html = 1])
  • boolean $html: (optional) use html line endings
floorTime (line 517)

round time down to the nearest $g time-granularity measure

Example: if this date time is set to 2005-11-21 17:48 and $g represents 00:15:00 (i.e. 15 minutes) then this date-time would be set to 2005-11-21 17:45 by rounding to the nearest 15 minutes.

void floorTime (SimpleTime $g)
getLongDateString (line 162)

get a long string representation for the current locale

  • return: time value in long time format
string getLongDateString ()
getLongDateTimeString (line 190)

get a long string representation for the current locale

  • return: time value in long time format
string getLongDateTimeString ()
getLongTimeString (line 176)

get a long string representation for the current locale

  • return: time value in long time format
string getLongTimeString ()
getShortDateString (line 120)

get a short string representation for the current locale

  • return: time value in short time format
string getShortDateString ()
getShortDateTimeString (line 148)

get a short string representation for the current locale

  • return: time value in short time format
string getShortDateTimeString ()
getShortTimeString (line 134)

get a short string representation for the current locale

  • return: time value in short time format
string getShortTimeString ()
getStringByFormat (line 228)

Get a string representation of this time in the specified format

Recognised format characters are as follows:

d Day of the month, 2 digits with leading zeros 01 to 31 D A textual representation of a day, three letters Mon through Sun j Day of the month without leading zeros 1 to 31 l (lowercase 'L') A full textual representation of the day of the week Sunday through Saturday

F A full textual representation of a month, such as January or March January through December m Numeric representation of a month, with leading zeros 01 through 12 M A short textual representation of a month, three letters Jan through Dec n Numeric representation of a month, without leading zeros 1 through 12

Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003 y A two digit representation of a year Examples: 99 or 03

a Lowercase Ante meridiem and Post meridiem am or pm A Uppercase Ante meridiem and Post meridiem AM or PM g 12-hour format of an hour without leading zeros 1 through 12 G 24-hour format of an hour without leading zeros 0 through 23 h 12-hour format of an hour with leading zeros 01 through 12 H 24-hour format of an hour with leading zeros 00 through 23 i Minutes with leading zeros 00 to 59 s Seconds, with leading zeros 00 through 59

  • return: time value in short time format
string getStringByFormat ( $format)
  • $format
max (line 504)

Sets this SimpleDate to the later of $this and $t

void max (SimpleDate $t)
min (line 495)

Sets this SimpleDate to the earlier of $this and $t

void min (SimpleDate $t)
monthRound (line 368)

round (down) the date-time to the start of the current month (the 1st)

void monthRound ()
moy (line 609)

return integer month of year (1..12)

  • return: month of year (1..12)
integer moy ()
moyShortStr (line 625)

return the (short) month of the year of the current date as a string (in current language)

  • return: month of the year (Jan, Feb etc)
string moyShortStr ()
moyStr (line 617)

return the month of year of the current date as a string (in current language)

  • return: month of the year (January, February etc)
string moyStr ()
partDaysBetween (line 427)

returns the number of days (or part thereof) between two dates ($this - $d)

void partDaysBetween (SimpleDate $date)
  • SimpleDate $date: date to subtract from this date
quarterRound (line 376)

round (down) the date-time to the start of the current quarter (1st Jan, 1st Apr, 1st Jul, 1st Oct)

void quarterRound ()
setStr (line 89)

set the date and time from a string

  • YYYY-MM-DD (assumes 00:00:00)
  • YYYY-MM-DD HH:MM (assumes :00)
  • YYYY-MM-DD HH:MM:SS

void setStr (mixed $s)
  • mixed $s: date time string
setTicks (line 295)

set the date and time from seconds since epoch

void setTicks (mixed $t)
  • mixed $t: ticks
setTime (line 469)

Sets the time component of this date-time to the specified time but with the same date as currently set

The specified time can be HH:MM HH:MM:SS, seconds since midnight or a SimpleTime object

void setTime (mixed $s)
  • mixed $s: time to use
setTimeParts (line 561)

Set current date-time by components

void setTimeParts (integer $sec, integer $min, integer $hour, integer $day, integer $month, integer $year)
  • integer $sec: (optional) seconds to set
  • integer $min: (optional) minutes to set
  • integer $hour: (optional) hours to add set
  • integer $day: (optional) days to add set
  • integer $month: (optional) months to set
  • integer $year: (optional) years to set
subtract (line 448)

returns the number of seconds between two times

NB this does not specially account for daylight saving changes, so will not always give the 24*60*60 for two datetimes that are 1 day apart on the calendar...!

void subtract (SimpleDate $date)
  • SimpleDate $date: date to subtract from this date
timePart (line 458)

returns a SimpleTime object for just the time component of this date time

  • return: object of just the HH:MM:SS component of this date
SimpleTime timePart ()
timeString (line 101)
void timeString ()
weekRound (line 360)

round (down) the date-time to the start of the current week (Sunday)

void weekRound ()
year (line 642)

four-digit year (YYYY)

  • return: year (e.g. 2005)
integer year ()
yearRound (line 385)

round (down) the date-time to the start of the current year (1st Jan)

void yearRound ()
_setTicks (line 302)
void _setTicks ( $s)
  • $s
_T_ (line 663)

translate an individual date-related word (day of week, month of year)

  • return: translated word
string _T_ (string $word)
  • string $word: word to translate

Documentation generated on Tue, 06 Mar 2007 10:01:12 +0000 by phpDocumentor 1.3.0