DateClass

Author: Steve Powell
Copyright: (c) 2004 ScrimpNet.com
License: GNU Lesser General Public License

Description

This class allows you to add a period to a date. You can also retrieve periods such as begin/end of month, begin/end of week, and begin/end of quarters.

Member Summary

Public member functions. See class source for more detailed descriptions.

Member / Function
Return Type
 
DateClass([$dateTime])
DateClass (constructor)
Create a new instance of the class
Add($datepart,$adjustValue,
[$dateTime])
DateClass

Returns reference to this class after adding <$adjustValue> periods. Periods are set in $datePart. If <$adjustValue> is negative value is subtracted from class.

<$datePart> can be common keys for php.date() and php.getdate().

year | years | y
months | month | mon
days | day | mday
hours | hour | g
minutes | minute | i
seconds | second | s

For more valid periods see function comments.

SetDate([$dateTime])
DateClass
Changes class date and returns reference to class. If <$dateTime> is not provided then defaults to current time().
DatePart($datePart,[$dateTime])
mixed
Returns the php.getdate() value for this class. <$datePart> must be a valid parameter for getdate().
Year([$dateTime])
integer
Return year for class
Month([$dateTime])
integer
Return month of year for class (1-12)
Day([$dateTime])
integer
Return day of month for class (1-31)
Hours([$dateTime])
integer
Return hours past midnight for class (0-23)
Minutes([$dateTime])
integer

Return minutes past the hour for class (0-59)

Seconds([$dateTime])
integer
Return seconds past the minute for class (0-59)
TimeStamp([$dateTime])
integer
Return PHP timestamp value for class
BOW([$dateTime])
DateClass
Beginning of Week
Return first day of week based on date value of class
EOW([$dateTime])
DateClass

End of Week
Return last day of week based on date value of class

BOM([$dateTime])
DateClass

Beginning of Month
Return first day of month based on date value of class

EOM([$dateTime])
DateClass
End of Month
Return last day of month based on date value of class
Quarter([$dateTime])
integer
Return calendar quarter date value of class is in. (1-4)
BOQ([$dateTime])
DateClass

Beginning of Quarter
Return first day of quarter based on date value of class

EOQ([$dateTime])
DateClass
End of Quarter
Return last day of quarter based on date value of class
BOY([$dateTime])
DateClass
Beginning of Year
Return first day of calendar year based on date value of class
EOY([$dateTime])
DateClass
End of Year
Return last day of calendar year based on date value of class
ToString([$format],[$dateTime])
DateClass

Return a formatted string of the date value of class. Use <$format> if provided. If not provided then use last provided format or default format set during class initialization.

The following predefined formats are available:

"RFC822" Mon, 17 May 2004 20:55:42 -0400
"RSS_1.0" 2004-05-17T20:55:42-0400
"HTTP" Mon, 17 May 2004 20:55:42 GMT
"RFC1123" Mon, 17 May 2004 20:55:42 GMT

UTC([$dateTime])
DateClass
Return UTC equivelent time for date value of class

Notes

Most functions take an optional <$dateTime> parameter. If this parameter is
used it will adjust the class value to <$dateTime> before performing the
requested action. <$dateTime> can be:

string 14-JAN-2004
5/15/2004
2004-03-12 17:35
any format that can be parsed by PHP.strtotime() using GNU date syntax. These are only examples
integer 1072879687 PHP timestamp
object DateClass existing DateClass object

Customization Hints & Ideas

    1. This source code contains many functions you may not need and the code is
      thoroughly commented. You are free to remove any function or comments you
      don't need but you MAY NOT remove the licensing or copyright information.
    2. The _parseDate() function is responsible for taking input and converting
      it into a PHP timestamp value. Modify this routine to allow class to
      be able to handle more date formats
    3. Expand class to have better UTC or timezone awareness
    4. Allow class to handle years that begin on different months
      i.e. Fiscal year starting 4/1/xxxx or 10/1/xxxx
    5. Customize your own predefined string formats

DateSpanClass

Author: Steve Powell
Copyright: (c) 2004 ScrimpNet.com
License: GNU Lesser General Public License

Description

This class allows you to determine the span between two dates. The span can be a wide variety of different kinds of periods including year, month, week, weekdays, & quarters.

Prerequisites

This class depends on access to DateClass

Member Functions

Public member functions. See class source for more detailed descriptions.

Member / Function
Return Type
 
DateSpanClass([$dateStart],[$dateStop])
(constructor)
Create a DateSpan to calculate difference between two dates. Usually optional parameters are not supplied during class construction. Instead the target dates are supplied when calling one of the accessor functions.
Span($period,[$dateStart],[$dateStop])
mixed

Calculate span between two dates. Returned value is determined by <$period>. Numbers can be integer or float depending on result.

<$period> can be common keys for php.date() and php.getdate().

year | years | y
quarters | q
months | month | mon
weeks | w
weekdays | wday
days | day | mday | d
hours | hour | g
minutes | minute | i
seconds | second | s
StartDate (property)
DateClass
Return DateClass of starting date in span
StopDate (property)
DateClass
Return DateClass of stopping date in span
Years([$dateStart],[$dateStop])
numeric
Return number of years covered by span
Quarters([$dateStart],[$dateStop])
integer
Return number of quarter boundries crossed in span
Months([$dateStart],[$dateStop])
integer
Return number of month boundries crossed in span
Weeks([$dateStart],[$dateStop])
numeric
Return number of 7-day periods covered by span
WeekDays([$dateStart],[$dateStop])
integer
Return number of weekdays (M-F) covered by span
Days([$dateStart],[$dateStop])
numeric
Return number of days covered by span
Hours([$dateStart],[$dateStop])
numeric
Return number of hours covered by span
Minutes([$dateStart],[$dateStop])
numeric
Return number of minutes covered by span
Seconds([$dateStart],[$dateStop])
integer
Return number of seconds covered by span
ToString([$format])
string
Return formatted string of the current timestamp. Use default format until <$format> is provided then use new format for each call.

Most functions take optional <$startDate> and <$stopDate> parameters. If these parameters are
provided, the span will adjust to these new end points before returning any value. If no parameters are passed the existing span will be used.

string 14-JAN-2004
5/15/2004
2004-03-12 17:35
any format that can be parsed by PHP.strtotime() using GNU date syntax. These are only examples
integer 1072879687 PHP timestamp
object DateClass existing DateClass object

Notes

    1. This source code contains many functions you may not need and the code is
      thoroughly commented. You are free to remove any function or comments you
      don't need but you MAY NOT remove the licensing or copyright information.
    2. Functions return positive value when StartDate < StopDate. Functions
      return negative values when StartDate > StopDate.
    3. For performance reasons, multiple calls to the class with the same
      span-start/span-stop dates (and/or times) are not recalculated.

Customization Hints & Ideas

    1. Expand class to have better UTC or timezone awareness
    2. Allow class to handle years that begin on different months
      i.e. Fiscal year starting 4/1/xxxx or 10/1/xxxx
    3. Customize your own predefined string formats