Class Date_Calc

Description

Date_Calc is a calendar class used to calculate and

manipulate calendar dates and retrieve dates in a calendar format. It does not rely on 32-bit system date stamps, so you can display calendars and compare dates that date pre 1970 and post 2038.

This source file is subject to version 2.02 of the PHP license, that is bundled with this package in the file LICENSE, and is available at through the world-wide-web at http://www.php.net/license/2_02.txt. If you did not receive a copy of the PHP license and are unable to obtain it through the world-wide-web, please send a note to license@php.net so we can mail you a copy immediately.

Copyright (c) 1999, 2002, 2003 ispi

Located in /maintenance/libraries/pear/Date/Calc.php (line 33)


	
			
Method Summary
 string beginOfMonth ([string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string beginOfNextMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string beginOfNextWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string beginOfPrevMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string beginOfPrevWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string beginOfWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 int compareDates (string $day1, string $month1, string $year1, string $day2, string $month2, string $year2)
 int dateDiff (string $day1, string $month1, string $year1, string $day2, string $month2, string $year2)
 string dateFormat (string $day, string $month, string $year, string $format)
 string dateNow ([string $format = '%Y%m%d'])
 float dateSeason (string $season, [string $year = ''])
 integer dateToDays (string $day, string $month, string $year)
 int dayOfWeek ([string $day = ''], [string $month = ''], [string $year = ''])
 int daysInMonth ([string $month = ''], [string $year = ''])
 string daysToDate (int $days, [string $format = '%Y%m%d'])
 string defaultCentury (string $year)
 string endOfNextMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string endOfPrevMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string endOfWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 int firstOfMonthWeekday ([string $month = ''], [string $year = ''])
 array getCalendarMonth ([string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 array getCalendarWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 array getCalendarYear ([string $year = ''], [string $format = '%Y%m%d'])
 string getDay ()
 string getMonth ()
 string getMonthAbbrname (string $month, [int $length = 3])
 integer getMonthFromFullName (string $month)
 string getMonthFullname (string $month)
 array getMonthNames ()
 string getWeekdayAbbrname ([string $day = ''], [string $month = ''], [string $year = ''], [int $length = 3])
 string getWeekdayFullname ([string $day = ''], [string $month = ''], [string $year = ''])
 array getWeekDays ()
 string getYear ()
 string gregorianToISO (string $day, string $month, string $year)
 boolean isFutureDate (string $day, string $month, string $year)
 boolean isLeapYear ([string $year = ''])
 boolean isPastDate (string $day, string $month, string $year)
 boolean isValidDate (string $day, string $month, string $year)
 int julianDate ([string $day = ''], [string $month = ''], [string $year = ''])
 string nextDay ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string nextDayOfWeek (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [boolean $format = '%Y%m%d'], [string $onOrAfter = false])
 string nextDayOfWeekOnOrAfter (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string nextWeekday ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string NWeekdayOfMonth (string $occurance, string $dayOfWeek, string $month, string $year, [string $format = '%Y%m%d'])
 string prevDay ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string prevDayOfWeek (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [boolean $format = '%Y%m%d'], [string $onOrBefore = false])
 string prevDayOfWeekOnOrBefore (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 string prevWeekday ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
 int quarterOfYear ([string $day = ''], [string $month = ''], [string $year = ''])
 integer weekOfYear ([string $day = ''], [string $month = ''], [string $year = ''])
 int weeksInMonth ([string $month = ''], [string $year = ''])
Methods
beginOfMonth (line 910)

Return date of first day of month of given date.

  • return: date in given format
  • access: public
string beginOfMonth ([string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
beginOfNextMonth (line 324)

Returns date of begin of next month of given date.

  • return: date in given format
  • access: public
string beginOfNextMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
beginOfNextWeek (line 1004)

Find the month day of the beginning of week after given date, using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)

  • return: date in given format
  • access: public
string beginOfNextWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
beginOfPrevMonth (line 398)

Returns date of the first day of previous month of given date.

  • return: date in given format
  • access: public
string beginOfPrevMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
beginOfPrevWeek (line 1046)

Find the month day of the beginning of week before given date, using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)

  • return: date in given format
  • access: public
string beginOfPrevWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
beginOfWeek (line 936)

Find the month day of the beginning of week for given date, using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of prev month.)

  • return: date in given format
  • access: public
string beginOfWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
compareDates (line 792)

Compares two dates

  • return: 0 on equality, 1 if date 1 is greater, -1 if smaller
  • access: public
int compareDates (string $day1, string $month1, string $year1, string $day2, string $month2, string $year2)
  • string $day1: day in format DD
  • string $month1: month in format MM
  • string $year1: year in format CCYY
  • string $day2: day in format DD
  • string $month2: month in format MM
  • string $year2: year in format CCYY
dateDiff (line 766)

Returns number of days between two given dates.

  • return: absolute number of days between dates, -1 if there is an error.
  • access: public
int dateDiff (string $day1, string $month1, string $year1, string $day2, string $month2, string $year2)
  • string $day1: day in format DD
  • string $month1: month in format MM
  • string $year1: year in format CCYY
  • string $day2: day in format DD
  • string $month2: month in format MM
  • string $year2: year in format CCYY
dateFormat (line 1342)

Formats the date in the given format, much like strfmt(). This function is used to alleviate the problem with 32-bit numbers for dates pre 1970 or post 2038, as strfmt() has on most systems.

Most of the formatting options are compatible.

formatting options:

%a abbreviated weekday name (Sun, Mon, Tue) %A full weekday name (Sunday, Monday, Tuesday) %b abbreviated month name (Jan, Feb, Mar) %B full month name (January, February, March) %d day of month (range 00 to 31) %e day of month, single digit (range 0 to 31) %E number of days since unspecified epoch (integer) (%E is useful for passing a date in a URL as an integer value. Then simply use daysToDate() to convert back to a date.) %j day of year (range 001 to 366) %m month as decimal number (range 1 to 12) %n newline character (\n) %t tab character (\t) %w weekday as decimal (0 = Sunday) %U week number of current year, first sunday as first week %y year as decimal (range 00 to 99) %Y year as decimal including century (range 0000 to 9999) %% literal '%'

  • return: date in given format
  • access: public
string dateFormat (string $day, string $month, string $year, string $format)
  • string $day: day in format DD
  • string $month: month in format MM
  • string $year: year in format CCYY
  • string $format: format for returned date
dateNow (line 47)

Returns the current local date. NOTE: This function retrieves the local date using strftime(), which may or may not be 32-bit safe on your system.

  • return: the current date in specified format
  • access: public
string dateNow ([string $format = '%Y%m%d'])
  • string $format: the strftime() format to return the date
dateSeason (line 1702)

Determines julian date of the given season Adapted from previous work in Java by James Mark Hamilton, mhamilton@qwest.net

float dateSeason (string $season, [string $year = ''])
  • string $season: is VERNALEQUINOX, SUMMERSOLSTICE, AUTUMNALEQUINOX, or WINTERSOLSTICE.
  • string $year: year in format CCYY, must be a calendar year between -1000BC and 3000AD.
dateToDays (line 1204)

Converts a date to number of days since a distant unspecified epoch.

  • return: number of days
  • access: public
integer dateToDays (string $day, string $month, string $year)
  • string $day: day in format DD
  • string $month: month in format MM
  • string $year: year in format CCYY
dayOfWeek (line 188)

Returns day of week for given date, 0=Sunday

  • access: public
int dayOfWeek ([string $day = ''], [string $month = ''], [string $year = ''])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
daysInMonth (line 813)

Find the number of days in the given month.

  • return: number of days
  • access: public
int daysInMonth ([string $month = ''], [string $year = ''])
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
daysToDate (line 1239)

Converts number of days to a distant unspecified epoch.

  • return: date in specified format
  • access: public
string daysToDate (int $days, [string $format = '%Y%m%d'])
  • int $days: number of days
  • string $format: format for returned date
defaultCentury (line 738)

Sets century for 2 digit year.

51-99 is 19, else 20

  • return: 4 digit year
  • access: public
string defaultCentury (string $year)
  • string $year: 2 digit year
endOfNextMonth (line 361)

Returns date of the last day of next month of given date.

  • return: date in given format
  • access: public
string endOfNextMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
endOfPrevMonth (line 435)

Returns date of the last day of previous month for given date.

  • return: date in given format
  • access: public
string endOfPrevMonth ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
endOfWeek (line 970)

Find the month day of the end of week for given date, using DATE_CALC_BEGIN_WEEKDAY. (can return weekday of following month.)

  • return: date in given format
  • access: public
string endOfWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
firstOfMonthWeekday (line 886)

Find the day of the week for the first of the month of given date.

  • return: number of weekday for the first day, 0=Sunday
  • access: public
int firstOfMonthWeekday ([string $month = ''], [string $year = ''])
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
getCalendarMonth (line 1124)

Return a set of arrays to construct a calendar month for the given date.

  • access: public
array getCalendarMonth ([string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
getCalendarWeek (line 1085)

Return an array with days in week

  • access: public
array getCalendarWeek ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
getCalendarYear (line 1175)

Return a set of arrays to construct a calendar year for the given date.

  • access: public
array getCalendarYear ([string $year = ''], [string $format = '%Y%m%d'])
  • string $year: year in format CCYY, default current local year
  • string $format: format for returned date
getDay (line 1450)

Returns the current local day in format DD

  • return: day in format DD
  • access: public
string getDay ()
getMonth (line 1437)

Returns the current local month in format MM

  • return: month in format MM
  • access: public
string getMonth ()
getMonthAbbrname (line 1492)

Returns the abbreviated month name for the given month

  • return: abbreviated month name
  • see: Date_Calc::getMonthFullname
  • access: public
string getMonthAbbrname (string $month, [int $length = 3])
  • string $month: month in format MM
  • int $length: optional length of abbreviation, default is 3
getMonthFromFullName (line 1571)

Returns the numeric month from the month name or an abreviation

Both August and Aug would return 8. Month name is case insensitive.

  • return: month number
integer getMonthFromFullName (string $month)
  • string $month: month name
getMonthFullname (line 1465)

Returns the full month name for the given month

  • return: full month name
  • access: public
string getMonthFullname (string $month)
  • string $month: month in format MM
getMonthNames (line 1594)

Returns an array of month names

Used to take advantage of the setlocale function to return language specific month names. XXX cache values to some global array to avoid preformace hits when called more than once.

  • return: An array of month names
array getMonthNames ()
getWeekdayAbbrname (line 1547)

Returns the abbreviated weekday name for the given date

  • return: full month name
  • see: Date_Calc::getWeekdayFullname
  • access: public
string getWeekdayAbbrname ([string $day = ''], [string $month = ''], [string $year = ''], [int $length = 3])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • int $length: optional length of abbreviation, default is 3
getWeekdayFullname (line 1515)

Returns the full weekday name for the given date

  • return: full month name
  • access: public
string getWeekdayFullname ([string $day = ''], [string $month = ''], [string $year = ''])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
getWeekDays (line 1612)

Returns an array of week days

Used to take advantage of the setlocale function to return language specific week days XXX cache values to some global array to avoid preformace hits when called more than once.

  • return: An array of week day names
array getWeekDays ()
getYear (line 1424)

Returns the current local year in format CCYY

  • return: year in format CCYY
  • access: public
string getYear ()
gregorianToISO (line 1635)

Converts from Gregorian Year-Month-Day to ISO YearNumber-WeekNumber-WeekDay

Uses ISO 8601 definitions. Algorithm from Rick McCarty, 1999 at http://personal.ecu.edu/mccartyr/ISOwdALG.txt

  • access: public
string gregorianToISO (string $day, string $month, string $year)
  • string $day: day in format DD
  • string $month: month in format MM
  • string $year: year in format CCYY
isFutureDate (line 122)

Determines if given date is a future date from now.

  • return: true/false
  • access: public
boolean isFutureDate (string $day, string $month, string $year)
  • string $day: day in format DD
  • string $month: month in format MM
  • string $year: year in format CCYY
isLeapYear (line 87)

Returns true for a leap year, else false

  • return: true/false
  • access: public
boolean isLeapYear ([string $year = ''])
  • string $year: year in format CCYY
isPastDate (line 155)

Determines if given date is a past date from now.

  • return: true/false
  • access: public
boolean isPastDate (string $day, string $month, string $year)
  • string $day: day in format DD
  • string $month: month in format MM
  • string $year: year in format CCYY
isValidDate (line 65)

Returns true for valid date, false for invalid date.

  • return: true/false
  • access: public
boolean isValidDate (string $day, string $month, string $year)
  • string $day: year in format CCYY
  • string $month: month in format MM
  • string $year: day in format DD
julianDate (line 259)

Returns number of days since 31 December of year before given date.

  • access: public
int julianDate ([string $day = ''], [string $month = ''], [string $year = ''])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
nextDay (line 680)

Returns date of day after given date.

  • return: date in given format
  • access: public
string nextDay ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
nextDayOfWeek (line 553)

Returns date of the next specific day of the week from the given date.

  • return: date in given format
  • access: public
string nextDayOfWeek (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [boolean $format = '%Y%m%d'], [string $onOrAfter = false])
  • int $dow: day of week, 0=Sunday
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • boolean $format: onOrAfter if true and days are same, returns current day
  • string $onOrAfter: format for returned date
nextDayOfWeekOnOrAfter (line 642)

Returns date of the next specific day of the week on or after the given date.

  • return: date in given format
  • access: public
string nextDayOfWeekOnOrAfter (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • int $dow: day of week, 0=Sunday
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
nextWeekday (line 473)

Returns date of the next weekday of given date, skipping from Friday to Monday.

  • return: date in given format
  • access: public
string nextWeekday ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
NWeekdayOfMonth (line 1285)

Calculates the date of the Nth weekday of the month, such as the second Saturday of January 2000.

  • return: date in given format
  • access: public
string NWeekdayOfMonth (string $occurance, string $dayOfWeek, string $month, string $year, [string $format = '%Y%m%d'])
  • string $occurance: occurance: 1=first, 2=second, 3=third, etc.
  • string $dayOfWeek: dayOfWeek: 0=Sunday, 1=Monday, etc.
  • string $month: month in format MM
  • string $year: year in format CCYY
  • string $format: format for returned date
prevDay (line 710)

Returns date of day before given date.

  • return: date in given format
  • access: public
string prevDay ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
prevDayOfWeek (line 598)

Returns date of the previous specific day of the week from the given date.

  • return: date in given format
  • access: public
string prevDayOfWeek (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [boolean $format = '%Y%m%d'], [string $onOrBefore = false])
  • int $dow: day of week, 0=Sunday
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • boolean $format: onOrBefore if true and days are same, returns current day
  • string $onOrBefore: format for returned date
prevDayOfWeekOnOrBefore (line 662)

Returns date of the previous specific day of the week on or before the given date.

  • return: date in given format
  • access: public
string prevDayOfWeekOnOrBefore (int $dow, [string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • int $dow: day of week, 0=Sunday
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
prevWeekday (line 512)

Returns date of the previous weekday, skipping from Monday to Friday.

  • return: date in given format
  • access: public
string prevWeekday ([string $day = ''], [string $month = ''], [string $year = ''], [string $format = '%Y%m%d'])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
  • string $format: format for returned date
quarterOfYear (line 294)

Returns quarter of the year for given date

  • access: public
int quarterOfYear ([string $day = ''], [string $month = ''], [string $year = ''])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
weekOfYear (line 230)

Returns week of the year, first Sunday is first day of first week

  • access: public
integer weekOfYear ([string $day = ''], [string $month = ''], [string $year = ''])
  • string $day: day in format DD, default is current local day
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year
weeksInMonth (line 852)

Returns the number of rows on a calendar month. Useful for determining the number of rows when displaying a typical month calendar.

  • return: number of weeks
  • access: public
int weeksInMonth ([string $month = ''], [string $year = ''])
  • string $month: month in format MM, default is current local month
  • string $year: year in format CCYY, default is current local year

Documentation generated on Fri, 3 Dec 2004 12:26:17 +0000 by phpDocumentor 1.3.0RC3