Date
[ class tree: Date ] [ index: Date ] [ all elements ]

Class: Date

Source Location: /Date-1.5.0a1/Date.php

Class Overview


Generic date handling class for PEAR


Author(s):

Version:

  • Release: 1.5.0a1

Copyright:

  • 1997-2007 Baba Buehler, Pierre-Alain Joye, Firman Wandayandi, C.A. Woodcock

Methods


Inherited Variables

Inherited Methods


Class Details

[line 254]
Generic date handling class for PEAR

Supports time zones with the Date_TimeZone class. Supports several operations from Date_Calc on Date objects.

Note to developers: the class stores the local time and date in the local standard time. That is, it does not store the time as the local Summer time when and if the time zone is in Summer time. It is much easier to store local standard time and remember to offset it when the user requests it.



[ Top ]


Method Detail

Date (Constructor)   [line 455]

void Date( [mixed $date = null], [bool $pb_countleapseconds = DATE_COUNT_LEAP_SECONDS])

Constructor

Creates a new Date Object initialized to the current date/time in the system-default timezone by default. A date optionally passed in may be in the ISO 8601, TIMESTAMP or UNIXTIME format, or another Date object. If no date is passed, the current date/time is used.

If a date is passed and an exception is returned by 'setDate()' there is nothing that this function can do, so for this reason, it is advisable to pass no parameter and to make a separate call to 'setDate()'. A date/time should only be passed if known to be a valid ISO 8601 string or a valid Unix timestamp.


Parameters:

mixed   $date     optional ISO 8601 date/time to initialize; or, a Unix time stamp
bool   $pb_countleapseconds     whether to count leap seconds (defaults to DATE_COUNT_LEAP_SECONDS)

[ Top ]

addDays   [line 3750]

void addDays( int $pn_days)

Converts the date to the specified no of days from the given date

To subtract days use a negative value for the '$pn_days' parameter

  • Since: Method available since Release 1.5.0
  • Access: public

Parameters:

int   $pn_days     days to add

[ Top ]

addHours   [line 3782]

void addHours( int $pn_hours)

Converts the date to the specified no of hours from the given date

To subtract hours use a negative value for the '$pn_hours' parameter

  • Since: Method available since Release 1.5.0
  • Access: public

Parameters:

int   $pn_hours     hours to add

[ Top ]

addMinutes   [line 3821]

void addMinutes( int $pn_minutes)

Converts the date to the specified no of minutes from the given date

To subtract minutes use a negative value for the '$pn_minutes' parameter

  • Since: Method available since Release 1.5.0
  • Access: public

Parameters:

int   $pn_minutes     minutes to add

[ Top ]

addMonths   [line 3718]

void addMonths( int $pn_months)

Converts the date to the specified no of months from the given date

To subtract months use a negative value for the '$pn_months' parameter

  • Since: Method available since Release 1.5.0
  • Access: public

Parameters:

int   $pn_months     months to add

[ Top ]

addSeconds   [line 3861]

void addSeconds( mixed $sec, [bool $pb_countleap = null])

Adds a given number of seconds to the date
  • Access: public

Parameters:

mixed   $sec     the no of seconds to add as integer or float
bool   $pb_countleap     whether to count leap seconds (defaults to value of count-leap-second object property)

[ Top ]

addSpan   [line 4052]

void addSpan( object $span)

Adds a time span to the date

A time span is defined as a unsigned no of days, hours, minutes and seconds, where the no of minutes and seconds must be less than 60, and the no of hours must be less than 24.

A span is added (and subtracted) according to the following logic:

Hours, minutes and seconds are added such that if they fall over a leap second, the leap second is ignored, and not counted. For example, if a leap second occurred at 23.59.60, the following calculations:

23.59.59 + one second 23.59.00 + one minute 23.00.00 + one hour

would all produce 00.00.00 the next day.

A day is treated as equivalent to 24 hours, so if the clocks went backwards at 01.00, and one day was added to the time 00.30, the result would be 23.30 the same day.

This is the implementation which is thought to yield the behaviour that the user is most likely to expect, or in another way of looking at it, it is the implementation that produces the least unexpected behaviour. It basically works in hours, that is, a day is treated as exactly equivalent to 24 hours, and minutes and seconds are treated as equivalent to 1/60th and 1/3600th of an hour. It should be obvious that working in days is impractical; working in seconds is problematic when it comes to adding days that fall over leap seconds, where it would appear to most users that the function adds only 23 hours, 59 minutes and 59 seconds. It is also problematic to work in any kind of mixture of days, hours, minutes, and seconds, because then the addition of a span would sometimes depend on which order you add the constituent parts, which undermines the concept of a span altogether.

If you want alternative functionality, you must use a mixture of the following functions instead:

addYears() addMonths() addDays() addHours() addMinutes() addSeconds()

  • Access: public

Parameters:

object   $span     the time span to add

[ Top ]

addYears   [line 3685]

void addYears( int $pn_years)

Converts the date to the specified no of years from the given date

To subtract years use a negative value for the '$pn_years' parameter

  • Since: Method available since Release 1.5.0
  • Access: public

Parameters:

int   $pn_years     years to add

[ Top ]

after   [line 4366]

boolean after( object $when)

Test if this date/time is after a certain date/time
  • Return: true if this date is after $when
  • Access: public

Parameters:

object   $when     the Date object to test against

[ Top ]

before   [line 4341]

boolean before( object $when)

Test if this date/time is before a certain date/time
  • Return: true if this date is before $when
  • Access: public

Parameters:

object   $when     the Date object to test against

[ Top ]

compare   [line 4278]

int compare( object $od1, object $od2)

Compares two dates

Suitable for use in sorting functions.

  • Return: 0 if the dates are equal, -1 if '$od1' is before '$od2', 1 if '$od1' is after '$od2'
  • Access: public

Parameters:

object   $od1     the first Date object to compare
object   $od2     the second Date object to compare

[ Top ]

convertTZ   [line 3541]

void convertTZ( object $tz)

Converts this date to a new time zone

Previously this might not have worked correctly if your system did not allow putenv() or if localtime() did not work in your environment, but this implementation is no longer used.


Parameters:

object   $tz     Date_TimeZone object to convert to

[ Top ]

convertTZByID   [line 3616]

void convertTZByID( string $ps_id)

Converts this date to a new time zone, given a valid time zone ID

Previously this might not have worked correctly if your system did not allow putenv() or if localtime() does not work in your environment, but this implementation is no longer used.


Parameters:

string   $ps_id     a valid time zone id, e.g. 'Europe/London'

[ Top ]

copy   [line 489]

void copy( object $date)

Copy values from another Date object

Makes this Date a copy of another Date object. This is a PHP4-compatible implementation of '__clone()' in PHP5.

  • Access: public

Parameters:

object   $date     Date object to copy

[ Top ]

dateDiff   [line 4189]

mixed dateDiff( object $po_date, [bool $pb_ignoretime = false])

Subtract supplied date and return answer in days

If the second parameter '$pb_ignoretime' is specified as false, the time parts of the two dates will be ignored, and the integral no of days between the day-month-year parts of the two dates will be returned. If either of the two dates have an invalid time, the integral no of days will also be returned, else the returned value will be the no of days as a float, with each hour being treated as 1/24th of a day and so on.

For example, 21/11/2007 13.00 minus 21/11/2007 01.00 returns 0.5

Note that if the passed date is in the past, a positive value will be returned, and if it is in the future, a negative value will be returned.

  • Return: days between two dates as int or float
  • Since: Method available since Release 1.5.0
  • Access: public

Parameters:

object   $po_date     date to subtract
bool   $pb_ignoretime     whether to ignore the time values of the two dates in subtraction (defaults to false)

[ Top ]

equals   [line 4391]

boolean equals( object $when)

Test if this date/time is exactly equal to a certain date/time
  • Return: true if this date is exactly equal to $when
  • Access: public

Parameters:

object   $when     the Date object to test against

[ Top ]

format   [line 1220]

string format( string $format)

Date pretty printing, similar to strftime()

Formats the date in the given format, much like strftime(). Most strftime() options are supported.

Formatting options:

  1. %a
abbreviated weekday name (Sun, Mon, Tue)
  1. %A
full weekday name (Sunday, Monday, Tuesday)
  1. %b
abbreviated month name (Jan, Feb, Mar)
  1. %B
full month name (January, February, March)
  1. %C
century number (the year divided by 100 and truncated to an integer, range 00 to 99)
  1. %d
day of month (range 00 to 31)
  1. %D
equivalent to "%m/%d/%y"
  1. %e
day of month without leading noughts (range 0 to 31)
  1. %E
Julian day - no of days since Monday, 24th November, 4714 B.C. (in the proleptic Gregorian calendar)
  1. %g
like %G, but without the century
  1. %G
the 4-digit year corresponding to the ISO week number (see %V). This has the same format and value as %Y, except that if the ISO week number belongs to the previous or next year, that year is used instead.
  1. %h
hour as decimal number without leading noughts (0 to 23)
  1. %H
hour as decimal number (00 to 23)
  1. %i
hour as decimal number on 12-hour clock without leading noughts (1 to 12)
  1. %I
hour as decimal number on 12-hour clock (01 to 12)
  1. %j
day of year (range 001 to 366)
  1. %m
month as decimal number (range 01 to 12)
  1. %M
minute as a decimal number (00 to 59)
  1. %n
newline character ("\n")
  1. %o
raw timezone offset expressed as '+/-HH:MM'
  1. %O
dst-corrected timezone offset expressed as '+/-HH:MM'
  1. %p
either 'am' or 'pm' depending on the time
  1. %P
either 'AM' or 'PM' depending on the time
  1. %r
time in am/pm notation; equivalent to "%I:%M:%S %p"
  1. %R
time in 24-hour notation; equivalent to "%H:%M"
  1. %s
seconds including the micro-time (the decimal representation less than one second to six decimal places
  1. %S
seconds as a decimal number (00 to 59)
  1. %t
tab character ("\t")
  1. %T
current time; equivalent to "%H:%M:%S"
  1. %u
day of week as decimal (1 to 7; where 1 = Monday)
  1. %U
week number of the current year as a decimal number, starting with the first Sunday as the first day of the first week (i.e. the first full week of the year, and the week that contains 7th January) (00 to 53)
  1. %V
the ISO 8601:1988 week number of the current year as a decimal number, range 01 to 53, where week 1 is the first week that has at least 4 days in the current year, and with Monday as the first day of the week. (Use %G or %g for the year component that corresponds to the week number for the specified timestamp.)
  1. %w
day of week as decimal (0 to 6; where 0 = Sunday)
  1. %W
week number of the current year as a decimal number, starting with the first Monday as the first day of the first week (i.e. the first full week of the year, and the week that contains 7th January) (00 to 53)
  1. %y
year as decimal (range 00 to 99)
  1. %Y
year as decimal including century (range 0000 to 9999)
  1. %Z
Abbreviated form of time zone name, e.g. 'GMT', or the abbreviation for Summer time if the date falls in Summer time, e.g. 'BST'.
  1. %%
literal '%'

The following codes render a different output to that of 'strftime()':

  1. %e
in 'strftime()' a single digit is preceded by a space
  1. %h
in 'strftime()' is equivalent to '%b'
  1. %U
'%U' and '%W' are different in 'strftime()' in that if week 1 does not start on 1st January, '00' is returned, whereas this function returns '53', that is, the week is counted as the last of the previous year.
  1. %W

  • Return: date/time in given format
  • Access: public

Parameters:

string   $format     the format string for returned date/time

[ Top ]

format2   [line 1953]

string format2( string $ps_format, [string $ps_locale = "en_GB"])

Extended version of 'format()' with variable-length formatting codes

Most codes reproduce the no of digits equal to the length of the code, for example, 'YYY' will return the last 3 digits of the year, and so the year 2007 will produce '007', and the year 89 will produce '089', unless the no-padding code is used as in 'NPYYY', which will return '89'.

For negative values, the sign will be discarded, unless the 'S' code is used in combination, but note that for positive values the value will be padded with a leading space unless it is suppressed with the no-padding modifier, for example for 2007:

  1. YYYY
returns '2007'
  1. SYYYY
returns ' 2007'
  1. NPSYYYY
returns '2007'

The no-padding modifier 'NP' can be used with numeric codes to suppress leading (or trailing in the case of code 'F') noughts, and with character-returning codes such as 'DAY' to suppress trailing spaces, which will otherwise be padded to the maximum possible length of the return-value of the code; for example, for Monday:

  1. Day
returns 'Monday ' because the maximum length of this code is 'Wednesday';
  1. NPDay
returns 'Monday'

N.B. this code affects the code immediately following only, and without this code the default is always to apply padding.

Most character-returning codes, such as 'MONTH', will set the capitalization according to the code, so for example:

  1. MONTH
returns upper-case spelling, e.g. 'JANUARY'
  1. Month
returns spelling with first character of each word capitalized, e.g. 'January'
  1. month
returns lower-case spelling, e.g. 'january'

Where it makes sense, numeric codes can be combined with a following 'SP' code which spells out the number, or with a 'TH' code, which renders the code as an ordinal ('TH' only works in English), for example, for 31st December:

  1. DD
returns '31'
  1. DDTH
returns '31ST'
  1. DDth
returns '31st'
  1. DDSP
returns 'THIRTY-ONE'
  1. DDSp
returns 'Thirty-one'
  1. DDsp
returns 'thirty-one'
  1. DDSPTH
returns 'THIRTY-FIRST'
  1. DDSpth
returns 'Thirty-first'
  1. DDspth
returns 'thirty-first'

All formatting options:

  1. -
All punctuation and white-space is reproduced unchanged
  1. /
  1. ,
  1. .
  1. ;
  1. :
    1. "text"
    Quoted text is reproduced unchanged (escape using '\')
    1. AD
    AD indicator with or without full stops; N.B. if you are using 'Astronomical' year numbering then 'A.D./B.C.' indicators will be out for negative years
    1. A.D.
    1. AM
    Meridian indicator with or without full stops
    1. A.M.
    1. BC
    BC indicator with or without full stops
    1. B.C.
    1. BCE
    BCE indicator with or without full stops
    1. B.C.E.
    1. CC
    Century, i.e. the year divided by 100, discarding the remainder; 'S' prefixes negative years with a minus sign
    1. SCC
    1. CE
    CE indicator with or without full stops
    1. C.E.
    1. D
    Day of week (0-6), where 0 represents Sunday
    1. DAY
    Name of day, padded with blanks to display width of the widest name of day in the locale of the machine
    1. DD
    Day of month (1-31)
    1. DDD
    Day of year (1-366)
    1. DY
    Abbreviated name of day
    1. FFF
    Fractional seconds; no radix character is printed. The no of 'F's determines the no of digits of the part-second to return; e.g. 'HH:MI:SS.FF'
    1. F[integer]
    The integer after 'F' specifies the number of digits of the part-second to return. This is an alternative to using F[integer], and 'F3' is thus equivalent to using 'FFF'.
    1. HH
    Hour of day (0-23)
    1. HH12
    Hour of day (1-12)
    1. HH24
    Hour of day (0-23)
    1. ID
    Day of week (1-7) based on the ISO standard
    1. IW
    Week of year (1-52 or 1-53) based on the ISO standard
    1. IYYY
    4-digit year based on the ISO 8601 standard; 'S' prefixes negative years with a minus sign
    1. SIYYY
    1. IYY
    Last 3, 2, or 1 digit(s) of ISO year
    1. IY
    1. I
    1. J
    Julian day - the number of days since Monday, 24th November, 4714 B.C. (proleptic Gregorian calendar)
    1. MI
    Minute (0-59)
    1. MM
    Month (01-12; January = 01)
    1. MON
    Abbreviated name of month
    1. MONTH
    Name of month, padded with blanks to display width of the widest name of month in the date language used for
    1. PM
    Meridian indicator with or without full stops
    1. P.M.
    1. Q
    Quarter of year (1, 2, 3, 4; January - March = 1)
    1. RM
    Roman numeral month (I-XII; January = I); N.B. padded with leading spaces.
    1. SS
    Second (0-59)
    1. SSSSS
    Seconds past midnight (0-86399)
    1. TZC
    Abbreviated form of time zone name, e.g. 'GMT', or the abbreviation for Summer time if the date falls in Summer time, e.g. 'BST'. N.B. this is not a unique identifier - for this purpose use the time zone region (code 'TZR').
    1. TZH
    Time zone hour; 'S' prefixes the hour with the correct sign, (+/-), which otherwise is not displayed. Note that the leading nought can be suppressed with the no-padding code 'NP'). Also note that if you combine with the 'SP' code, the sign will not be spelled out. (I.e. 'STZHSp' will produce '+One', for example, and not 'Plus One'. 'TZH:TZM' will produce, for example, '+05:30'. (Also see 'TZM' format code)
    1. STZH
    1. TZI
    Whether or not the date is in Summer time (daylight saving time). Returns '1' if Summer time, else '0'.
    1. TZM
    Time zone minute, without any +/- sign. (Also see 'TZH' format element)
    1. TZN
    Long form of time zone name, e.g. 'Greenwich Mean Time', or the name of the Summer time if the date falls in Summer time, e.g. 'British Summer Time'. N.B. this is not a unique identifier - for this purpose use the time zone region (code 'TZR').
    1. TZO
    Time zone offset in ISO 8601 form - that is, 'Z' if UTC, else [+/-][hh]:[mm] (which would be equivalent to 'STZH:TZM'). Note that this result is right padded with spaces by default, (i.e. if 'Z').
    1. TZS
    Time zone offset in seconds; 'S' prefixes negative sign with minus sign '-' if negative, and no sign if positive (i.e. -43200 to 50400).
    1. STZS
    1. TZR
    Time zone region, that is, the name or ID of the time zone e.g. 'Europe/London'. This value is unique for each time zone.
    1. U
    Seconds since the Unix Epoch - January 1 1970 00:00:00 GMT
    1. W
    'Absolute' week of month (1-5), counting week 1 as 1st-7th of the year, regardless of the day
    1. W1
    Week of year (1-54), counting week 1 as the week that contains 1st January
    1. W4
    Week of year (1-53), counting week 1 as the week that contains 4th January (i.e. first week with at least 4 days)
    1. W7
    Week of year (1-53), counting week 1 as the week that contains 7th January (i.e. first full week)
    1. WW
    'Absolute' week of year (1-53), counting week 1 as 1st-7th of the year, regardless of the day
    1. YEAR
    Year, spelled out; 'S' prefixes negative years with 'MINUS'; N.B. 'YEAR' differs from 'YYYYSP' in that the first will render 1923, for example, as 'NINETEEN TWENTY-THREE, and the second as 'ONE THOUSAND NINE HUNDRED TWENTY-THREE'
    1. SYEAR
    1. YYYY
    4-digit year; 'S' prefixes negative years with a minus sign
    1. SYYYY
    1. YYY
    Last 3, 2, or 1 digit(s) of year
    1. YY
    1. Y
    1. Y,YYY
    Year with thousands-separator in this position; five possible separators
    1. Y.YYY
    1. Y·YYY
    N.B. space-dot (mid-dot, interpunct) is valid only in ISO 8859-1 (so take care when using UTF-8 in particular)
    1. YYYY
    1. Y YYY

    In addition the following codes can be used in combination with other codes; Codes that modify the next code in the format string:

    1. NP
    'No Padding' - Returns a value with no trailing blanks and no leading or trailing noughts; N.B. that the default is to include this padding in the return string. N.B. affects the code immediately following only.

    Codes that modify the previous code in the format string (can only be used with integral codes such as 'MM'):

    1. TH
    Ordinal number
    1. SP
    Spelled cardinal number
    1. SPTH
    Spelled ordinal number (combination of 'SP' and 'TH' in any order)
    1. THSP

    Code 'SP' can have the following three variations (which can also be used in combination with 'TH'):

    1. SP
    returns upper-case spelling, e.g. 'FOUR HUNDRED'
    1. Sp
    returns spelling with first character of each word capitalized, e.g. 'Four Hundred'
    1. sp
    returns lower-case spelling, e.g. 'four hundred'

    Code 'TH' can have the following two variations (although in combination with code 'SP', the case specification of 'SP' takes precedence):

    1. TH
    returns upper-case ordinal suffix, e.g. 400TH
    1. th
    returns lower-case ordinal suffix, e.g. 400th

    • Return: date/time in given format
    • Since: Method available since Release 1.5.0
    • Access: public

    Parameters:

    string   $ps_format     format string for returned date/time
    string   $ps_locale     language name abbreviation used for formatting numbers as spelled-out words

    [ Top ]

    format3   [line 3077]

    string format3( string $ps_format)

    Formats the date in the same way as 'format()', but using the formatting codes used by the PHP function 'date()'

    All 'date()' formatting options are supported except 'B'. This function also responds to the DATE_* constants, such as DATE_COOKIE, which are specified at:

    http://www.php.net/manual/en/ref.datetime.php#datetime.constants

    Formatting options:

    (Day)

    1. d
    Day of the month, 2 digits with leading zeros (01 to 31)
    1. D
    A textual representation of a day, three letters ('Mon' to 'Sun')
    1. j
    Day of the month without leading zeros (1 to 31)
    1. l
    [lowercase 'L'] A full textual representation of the day of the week ('Sunday' to 'Saturday')
    1. N
    ISO-8601 numeric representation of the day of the week (1 (for Monday) to 7 (for Sunday))
    1. S
    English ordinal suffix for the day of the month, 2 characters ('st', 'nd', 'rd' or 'th')
    1. w
    Numeric representation of the day of the week (0 (for Sunday) to 6 (for Saturday))
    1. z
    The day of the year, starting from 0 (0 to 365)

    (Week)

    1. W
    ISO-8601 week number of year, weeks starting on Monday (00 to 53)

    (Month)

    1. F
    A full textual representation of a month ('January' to 'December')
    1. m
    Numeric representation of a month, with leading zeros (01 to 12)
    1. M
    A short textual representation of a month, three letters ('Jan' to 'Dec')
    1. n
    Numeric representation of a month, without leading zeros (1 to 12)
    1. t
    Number of days in the given month (28 to 31)

    (Year)

    1. L
    Whether it is a leap year (1 if it is a leap year, 0 otherwise)
    1. o
    ISO-8601 year number. This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.
    1. Y
    A full numeric representation of a year, 4 digits (0000 to 9999)
    1. y
    A two digit representation of a year (00 to 99)

    (Time)

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

    (Time Zone)

    1. e
    Timezone identifier, e.g. Europe/London
    1. I
    Whether or not the date is in Summer time (1 if Summer time, 0 otherwise)
    1. O
    Difference to Greenwich time (GMT) in hours, e.g. '+0200'
    1. P
    Difference to Greenwich time (GMT) with colon between hours and minutes, e.g. '+02:00'
    1. T
    Timezone abbreviation, e.g. 'GMT', 'EST'
    1. Z
    Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive. (-43200 to 50400)

    (Full Date/Time)

    1. c
    ISO 8601 date, e.g. '2004-02-12T15:19:21+00:00'
    1. r
    RFC 2822 formatted date, e.g. 'Thu, 21 Dec 2000 16:01:07 +0200'
    1. U
    Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)

    • Return: date/time in given format
    • Since: Method available since Release 1.5.0
    • Access: public

    Parameters:

    string   $ps_format     the format string for returned date/time

    [ Top ]

    getDate   [line 1075]

    string getDate( [int $format = DATE_FORMAT_ISO])

    Gets a string (or other) representation of this date

    Returns a date in the format specified by the DATE_FORMAT_* constants.

    • Return: the date in the requested format
    • Access: public

    Parameters:

    int   $format     format constant (DATE_FORMAT_*) of the output date

    [ Top ]

    getDay   [line 4747]

    int getDay( )

    Returns the day field of the date object
    • Return: the day
    • Access: public

    [ Top ]

    getDayName   [line 4586]

    string getDayName( [bool $abbr = false], [int $length = 3])

    Gets the full name or abbreviated name of this weekday
    • Return: name of this day
    • Access: public

    Parameters:

    bool   $abbr     abbreviate the name
    int   $length     length of abbreviation

    [ Top ]

    getDayOfWeek   [line 4508]

    int getDayOfWeek( )

    Gets the day of the week for this date (0 = Sunday)
    • Return: the day of the week (0 = Sunday)
    • Access: public

    [ Top ]

    getDayOfYear   [line 4493]

    int getDayOfYear( )

    Returns the no of days (1-366) since 31st December of the previous year
    • Return: an integer between 1 and 366
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getDaysInMonth   [line 4553]

    int getDaysInMonth( )

    Gets number of days in the month for this date
    • Return: number of days in this month
    • Access: public

    [ Top ]

    getHour   [line 4868]

    int getHour( )

    Returns the hour field of the date object
    • Return: the hour
    • Access: public

    [ Top ]

    getJulianDate   [line 4477]

    int getJulianDate( )

    Returns the no of days (1-366) since 31st December of the previous year

    N.B. this function does not return (and never has returned) the 'Julian Date', as described, for example, at:

    http://en.wikipedia.org/wiki/Julian_day

    If you want the day of the year (0-366), use 'getDayOfYear()' instead. If you want the true Julian Day, call one of the following:

    1. format("%E")
    1. format2("J")

    There currently is no function that calls the Julian Date (as opposed to the 'Julian Day'), although the Julian Day is an approximation.

    • Return: the Julian date
    • See: Date::getDayOfYear()
    • Deprecated: Method deprecated in Release 1.5.0
    • Access: public

    [ Top ]

    getMinute   [line 4886]

    int getMinute( )

    Returns the minute field of the date object
    • Return: the minute
    • Access: public

    [ Top ]

    getMonth   [line 4732]

    int getMonth( )

    Returns the month field of the date object
    • Return: the minute
    • Access: public

    [ Top ]

    getMonthName   [line 4612]

    string getMonthName( [boolean $abbr = false])

    Gets the full name or abbreviated name of this month
    • Return: name of this month
    • Access: public

    Parameters:

    boolean   $abbr     abbreviate the name

    [ Top ]

    getNextDay   [line 4633]

    object Date getNextDay( )

    Get a Date object for the day after this one

    The time of the returned Date object is the same as this time.

    • Return: object representing the next day
    • Access: public

    [ Top ]

    getNextWeekday   [line 4671]

    object Date getNextWeekday( )

    Get a Date object for the weekday after this one

    The time of the returned Date object is the same as this time.

    • Return: object representing the next week-day
    • Access: public

    [ Top ]

    getPartSecond   [line 4945]

    float getPartSecond( )

    Returns the part-second field of the date object
    • Return: the part-second
    • Since: Method available since Release 1.5.0
    • Access: protected

    [ Top ]

    getPrevDay   [line 4652]

    object Date getPrevDay( )

    Get a Date object for the day before this one

    The time of the returned Date object is the same as this time.

    • Return: object representing the previous day
    • Access: public

    [ Top ]

    getPrevWeekday   [line 4695]

    object Date getPrevWeekday( )

    Get a Date object for the weekday before this one

    The time of the returned Date object is the same as this time.

    • Return: object representing the previous week-day
    • Access: public

    [ Top ]

    getQuarterOfYear   [line 4538]

    int getQuarterOfYear( )

    Gets the quarter of the year for this date
    • Return: the quarter of the year (1-4)
    • Access: public

    [ Top ]

    getSecond   [line 4904]

    int getSecond( )

    Returns the second field of the date object
    • Return: the second
    • Access: public

    [ Top ]

    getSecondsPastMidnight   [line 4923]

    float getSecondsPastMidnight( )

    Returns the no of seconds since midnight (0-86400) as float
    • Return: float which is at least 0 and less than 86400
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardDay   [line 5002]

    int getStandardDay( )

    Returns the day field of the local standard time
    • Return: the day
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardHour   [line 5021]

    int getStandardHour( )

    Returns the hour field of the local standard time
    • Return: the hour
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardMinute   [line 5040]

    int getStandardMinute( )

    Returns the minute field of the local standard time
    • Return: the minute
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardMonth   [line 4983]

    int getStandardMonth( )

    Returns the month field of the local standard time
    • Return: the minute
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardPartSecond   [line 5101]

    float getStandardPartSecond( )

    Returns the part-second field of the local standard time
    • Return: the part-second
    • Since: Method available since Release 1.5.0
    • Access: protected

    [ Top ]

    getStandardSecond   [line 5059]

    int getStandardSecond( )

    Returns the second field of the local standard time
    • Return: the second
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardSecondsPastMidnight   [line 5079]

    float getStandardSecondsPastMidnight( )

    Returns the no of seconds since midnight (0-86400) of the local standard time as float
    • Return: float which is at least 0 and less than 86400
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getStandardYear   [line 4964]

    int getStandardYear( )

    Returns the year field of the local standard time
    • Return: the year
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getTime   [line 3226]

    int getTime( )

    Returns the date/time in Unix time() format

    Returns a representation of this date in Unix time() format. This may only be valid for dates from 1970 to ~2038.

    • Return: number of seconds since the unix epoch
    • Access: public

    [ Top ]

    getTZID   [line 3242]

    string getTZID( )

    Returns the unique ID of the time zone, e.g. 'America/Chicago'
    • Return: the time zone ID
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getTZLongName   [line 3419]

    string getTZLongName( )

    Returns the long name of the time zone

    Returns long form of time zone name, e.g. 'Greenwich Mean Time'. N.B. if the date falls in Summer time, the Summer time name will be returned instead, e.g. 'British Summer Time'.

    N.B. this is not a unique identifier for the time zone - for this purpose use the time zone ID.

    • Return: the long name of the time zone
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getTZOffset   [line 3479]

    int getTZOffset( )

    Returns the DST-corrected offset from UTC for the given date

    Gets the offset to UTC for a given date/time, taking into account daylight savings time, if the time zone observes it and if it is in effect.

    N.B. that the offset is calculated historically and in the future according to the current Summer time rules, and so this function is proleptically correct, but not necessarily historically correct. (Although if you want to be correct about times in the distant past, this class is probably not for you because the whole notion of time zones does not apply, and historically there are so many time zone changes, Summer time rule changes, name changes, calendar changes, that calculating this sort of information is beyond the scope of this package altogether.)

    • Return: the corrected offset to UTC in milliseconds
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getTZShortName   [line 3445]

    string getTZShortName( )

    Returns the short name of the time zone

    Returns abbreviated form of time zone name, e.g. 'GMT'. N.B. if the date falls in Summer time, the Summer time name will be returned instead, e.g. 'BST'.

    N.B. this is not a unique identifier - for this purpose use the time zone ID.

    • Return: the short name of the time zone
    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    getWeekOfYear   [line 4523]

    int getWeekOfYear( )

    Gets the week of the year for this date
    • Return: the week of the year
    • Access: public

    [ Top ]

    getWeeksInMonth   [line 4568]

    int getWeeksInMonth( )

    Gets the number of weeks in the month for this date
    • Return: number of weeks in this month
    • Access: public

    [ Top ]

    getYear   [line 4717]

    int getYear( )

    Returns the year field of the date object
    • Return: the year
    • Access: public

    [ Top ]

    inDaylightTime   [line 3503]

    boolean inDaylightTime( [bool $pb_repeatedhourdefault = false])

    Tests if this date/time is in DST

    Returns true if daylight savings time is in effect for this date in this date's time zone.

    • Return: true if DST is in effect for this date
    • Access: public

    Parameters:

    bool   $pb_repeatedhourdefault     value to return if repeated hour is specified (defaults to false)

    [ Top ]

    inEquivalentTimeZones   [line 4256]

    bool inEquivalentTimeZones( object $po_date1, object $po_date2)

    Tests whether two dates are in equivalent time zones

    Equivalence in this context consists in the time zones of the two dates having:

    an equal offset from UTC in both standard and Summer time (if the time zones observe Summer time) the same Summer time start and end rules, that is, the two time zones must switch from standard time to Summer time, and vice versa, on the same day and at the same time

    An example of two equivalent time zones is 'Europe/London' and 'Europe/Lisbon', which in London is known as GMT/BST, and in Lisbon as WET/WEST.

    • Return: true if the time zones are equivalent
    • Since: Method available since Release 1.5.0
    • Access: public

    Parameters:

    object   $po_date1     the first Date object to compare
    object   $po_date2     the second Date object to compare

    [ Top ]

    isFuture   [line 4414]

    boolean isFuture( )

    Determine if this date is in the future
    • Return: true if this date is in the future
    • Access: public

    [ Top ]

    isLeapYear   [line 4446]

    boolean isLeapYear( )

    Determine if the year in this date is a leap year
    • Return: true if this year is a leap year
    • Access: public

    [ Top ]

    isPast   [line 4430]

    boolean isPast( )

    Determine if this date is in the past
    • Return: true if this date is in the past
    • Access: public

    [ Top ]

    isTimeValid   [line 4853]

    bool isTimeValid( )

    Whether the stored time is valid as a local time

    An invalid time is one that lies in the 'skipped hour' at the point that the clocks go forward. Note that the stored date (i.e. the day/month/year, is always valid).

    The object is able to store an invalid time because a user might unwittingly and correctly store a valid time, and then add one day so as to put the object in the 'skipped' hour (when the clocks go forward). This could be corrected by a conversion to Summer time (by adding one hour); however, if the user then added another day, and had no need for or interest in the time anyway, the behaviour may be rather unexpected. And anyway in this situation, the time originally specified would now, two days on, be valid again.

    So this class allows an invalid time like this so long as the user does not in any way make use of or request the time while it is in this semi-invalid state, in order to allow for for the fact that he might be only interested in the date, and not the time, and in order not to behave in an unexpected way, especially without throwing an exception to tell the user about it.

    • Since: Method available since Release 1.5.0
    • Access: public

    [ Top ]

    round   [line 728]

    void round( [int $pn_precision = DATE_PRECISION_DAY], [bool $pb_correctinvalidtime = DATE_CORRECTINVALIDTIME_DEFAULT])

    Rounds the date according to the specified precision (defaults to nearest day)

    The precision parameter must be one of the following constants:

    N.B. the default is DATE_PRECISION_DAY

    The precision can also be specified as an integral offset from one of these constants, where the offset reflects a precision of 10 to the power of the offset greater than the constant. For example:

    rounds the date to the nearest 10 years
    rounds the date to the nearest 1000 years
    rounds the date to 1 decimal point of a second
    rounds the date to 3 decimal points of a second
    rounds the date to the nearest 10 seconds (thus it is equivalent to DATE_PRECISION_10SECONDS)

    • Since: Method available since Release 1.5.0
    • Access: public

    Parameters:

    int   $pn_precision     a 'DATE_PRECISION_*' constant
    bool   $pb_correctinvalidtime     whether to correct, by adding the local Summer time offset, the rounded time if it falls in the skipped hour (defaults to DATE_CORRECTINVALIDTIME_DEFAULT)

    [ Top ]

    roundSeconds   [line 875]

    void roundSeconds( [int $pn_precision = 0], [bool $pb_correctinvalidtime = DATE_CORRECTINVALIDTIME_DEFAULT])

    Rounds seconds up or down to the nearest specified unit

    N.B. this function is equivalent to calling:

    1. 'round(DATE_PRECISION_SECOND + $pn_precision)'

    • Since: Method available since Release 1.5.0
    • Access: public

    Parameters:

    int   $pn_precision     number of digits after the decimal point
    bool   $pb_correctinvalidtime     whether to correct, by adding the local Summer time offset, the rounded time if it falls in the skipped hour (defaults to DATE_CORRECTINVALIDTIME_DEFAULT)

    [ Top ]

    setDate   [line 577]

    void setDate( string $date, [int $format = DATE_FORMAT_ISO], [bool $pb_repeatedhourdefault = false])

    Sets the fields of a Date object based on the input date and format

    Format parameter should be one of the specified DATE_FORMAT_* constants:

    • Access: public

    Parameters:

    string   $date     input date
    int   $format     optional format constant (DATE_FORMAT_*) of the input date. This parameter is not needed, except to force the setting of the date from a Unix time-stamp (DATE_FORMAT_UNIXTIME).
    bool   $pb_repeatedhourdefault     value to return if repeated hour is specified (defaults to false)

    [ Top ]

    setDateTime   [line 5810]

    void setDateTime( int $pn_day, int $pn_month, int $pn_year, int $pn_hour, int $pn_minute, mixed $pm_second, [bool $pb_repeatedhourdefault = false])

    Sets all the fields of the date object (day, month, year, hour, minute and second)

    If specified year forms an invalid date, then PEAR error will be returned. Note that setting each of these fields separately may unintentionally return a PEAR error if a transitory date is invalid between setting these fields.

    N.B. if the repeated hour, due to the clocks going back, is specified, the default is to assume local standard time.


    Parameters:

    int   $pn_day     the day
    int   $pn_month     the month
    int   $pn_year     the year
    int   $pn_hour     the hour
    int   $pn_minute     the minute
    mixed   $pm_second     the second as integer or float
    bool   $pb_repeatedhourdefault     whether to assume Summer time if a repeated hour is specified (defaults to false)

    [ Top ]

    setDay   [line 5540]

    void setDay( int $d, [bool $pb_validate = DATE_VALIDATE_DATE_BY_DEFAULT])

    Sets the day field of the date object

    If specified year forms an invalid date, then PEAR error will be returned, unless the validation is over-ridden using the second parameter.


    Parameters:

    int   $d     the day
    bool   $pb_validate     whether to check that the new date is valid

    [ Top ]

    setDayMonthYear   [line 5582]

    void setDayMonthYear( int $d, int $m, int $y)

    Sets the day, month and year fields of the date object

    If specified year forms an invalid date, then PEAR error will be returned. Note that setting each of these fields separately may unintentionally return a PEAR error if a transitory date is invalid between setting these fields.


    Parameters:

    int   $d     the day
    int   $m     the month
    int   $y     the year

    [ Top ]

    setHour   [line 5621]

    void setHour( int $h, [bool $pb_repeatedhourdefault = false])

    Sets the hour field of the date object

    Expects an hour in 24-hour format.


    Parameters:

    int   $h     the hour
    bool   $pb_repeatedhourdefault     whether to assume Summer time if a repeated hour is specified (defaults to false)

    [ Top ]

    setHourMinuteSecond   [line 5757]

    void setHourMinuteSecond( int $h, int $m, mixed $s, [bool $pb_repeatedhourdefault = false])

    Sets the hour, minute, second and part-second fields of the date object

    N.B. if the repeated hour, due to the clocks going back, is specified, the default is to assume local standard time.


    Parameters:

    int   $h     the hour
    int   $m     the minute
    mixed   $s     the second as integer or float
    bool   $pb_repeatedhourdefault     whether to assume Summer time if a repeated hour is specified (defaults to false)

    [ Top ]

    setLocalTime   [line 5244]

    void setLocalTime( int $pn_day, int $pn_month, int $pn_year, int $pn_hour, int $pn_minute, int $pn_second, float $pn_partsecond, [bool $pb_repeatedhourdefault = false], [bool $pb_correctinvalidtime = DATE_CORRECTINVALIDTIME_DEFAULT])