Constants

DATE_SUNDAY

DATE_SUNDAY

DATE_MONDAY

DATE_MONDAY

DATE_TUESDAY

DATE_TUESDAY

DATE_WEDNESDAY

DATE_WEDNESDAY

DATE_THURSDAY

DATE_THURSDAY

DATE_FRIDAY

DATE_FRIDAY

DATE_SATURDAY

DATE_SATURDAY

MASK_SUNDAY

MASK_SUNDAY

MASK_MONDAY

MASK_MONDAY

MASK_TUESDAY

MASK_TUESDAY

MASK_WEDNESDAY

MASK_WEDNESDAY

MASK_THURSDAY

MASK_THURSDAY

MASK_FRIDAY

MASK_FRIDAY

MASK_SATURDAY

MASK_SATURDAY

MASK_WEEKDAYS

MASK_WEEKDAYS

MASK_WEEKEND

MASK_WEEKEND

MASK_ALLDAYS

MASK_ALLDAYS

MASK_SECOND

MASK_SECOND

MASK_MINUTE

MASK_MINUTE

MASK_HOUR

MASK_HOUR

MASK_DAY

MASK_DAY

MASK_MONTH

MASK_MONTH

MASK_YEAR

MASK_YEAR

MASK_ALLPARTS

MASK_ALLPARTS

DATE_DEFAULT

DATE_DEFAULT

DATE_JSON

DATE_JSON

Properties

$_year

$_year : integer

Year

Type

integer

$_month

$_month : integer

Month

Type

integer

$_mday

$_mday : integer

Day

Type

integer

$_hour

$_hour : integer

Hour

Type

integer

$_min

$_min : integer

Minute

Type

integer

$_sec

$_sec : integer

Second

Type

integer

$_timezone

$_timezone : string

String representation of the date's timezone.

Type

string

$_timezoneAliases

$_timezoneAliases : array

These aliases map Windows, Lotus, and other Timezone IDs to those understood by PHP.

Type

array

$_timezoneAbbreviations

$_timezoneAbbreviations : array

These aliases map timezone abbreviations to those understood by PHP.

Type

array

$_timezoneIdentifiers

$_timezoneIdentifiers : array

A list of (Olson) timezone identifiers understood by PHP.

Type

array

$_defaultFormat

$_defaultFormat : string

Default format for __toString()

Type

string

$_defaultSpecs

$_defaultSpecs : string

Default specs that are always supported.

Type

string

$_supportedSpecs

$_supportedSpecs : string

Internally supported strftime() specifiers.

Type

string

$_corrections

$_corrections : array

Map of required correction masks.

Type

array

$_formatCache

$_formatCache : 

Type

Methods

__construct()

__construct(  $date = null,   $timezone = null) 

Builds a new date object. If $date contains date parts, use them to initialize the object.

Recognized formats:

  • arrays with keys 'year', 'month', 'mday', 'day' 'hour', 'min', 'minute', 'sec'
  • objects with properties 'year', 'month', 'mday', 'hour', 'min', 'sec'
  • yyyy-mm-dd hh:mm:ss
  • yyyymmddhhmmss
  • yyyymmddThhmmssZ
  • yyyymmdd (might conflict with unix timestamps between 31 Oct 1966 and 03 Mar 1973)
  • unix timestamps
  • anything parsed by strtotime()/DateTime.

Parameters

$date
$timezone

Throws

\Horde_Date_Exception

__toString()

__toString() : string

Returns a simple string representation of the date object

Returns

string —

This object converted to a string.

toDateTime()

toDateTime() : \DateTime

Returns a DateTime object representing this object.

Returns

\DateTime

toDays()

toDays() : integer

Converts a date in the proleptic Gregorian calendar to the no of days since 24th November, 4714 B.C.

Returns the no of days since Monday, 24th November, 4714 B.C. in the proleptic Gregorian calendar (which is 24th November, -4713 using 'Astronomical' year numbering, and 1st January, 4713 B.C. in the proleptic Julian calendar). This is also the first day of the 'Julian Period' proposed by Joseph Scaliger in 1583, and the number of days since this date is known as the 'Julian Day'. (It is not directly to do with the Julian calendar, although this is where the name is derived from.)

The algorithm is valid for all years (positive and negative), and also for years preceding 4714 B.C.

Algorithm is from PEAR::Date_Calc

Returns

integer —

The number of days since 24th November, 4714 B.C.

fromDays()

fromDays(integer  $days) : \Horde_Date

Converts number of days since 24th November, 4714 B.C. (in the proleptic Gregorian calendar, which is year -4713 using 'Astronomical' year numbering) to Gregorian calendar date.

Returned date belongs to the proleptic Gregorian calendar, using 'Astronomical' year numbering.

The algorithm is valid for all years (positive and negative), and also for years preceding 4714 B.C. (i.e. for negative 'Julian Days'), and so the only limitation is platform-dependent (for 32-bit systems the maximum year would be something like about 1,465,190 A.D.).

N.B. Monday, 24th November, 4714 B.C. is Julian Day '0'.

Algorithm is from PEAR::Date_Calc

Parameters

integer $days

the number of days since 24th November, 4714 B.C.

Returns

\Horde_Date

A Horde_Date object representing the date.

__get()

__get(string  $name) : integer|string

Getter for the date and time properties.

Parameters

string $name

One of 'year', 'month', 'mday', 'hour', 'min', 'sec' or 'timezone' (since Horde_Date 2.0.0).

Returns

integer|string —

The property value, or null if not set.

__set()

__set(string  $name, integer|string  $value) 

Setter for the date and time properties.

Parameters

string $name

One of 'year', 'month', 'mday', 'hour', 'min', 'sec' or 'timezone' (since Horde_Date 2.0.0).

integer|string $value

The property value.

__isset()

__isset(string  $name) : \boolen

Returns whether a date or time property exists.

Parameters

string $name

One of 'year', 'month', 'mday', 'hour', 'min' or 'sec'.

Returns

\boolen —

True if the property exists and is set.

add()

add(  $factor) 

Adds a number of seconds or units to this date, returning a new Date object.

Parameters

$factor

sub()

sub(  $factor) 

Subtracts a number of seconds or units from this date, returning a new Horde_Date object.

Parameters

$factor

getTimezoneAlias()

getTimezoneAlias(string  $timezone) : string

Returns the normalized (Olson) timezone name of a timezone alias.

We currently support Windows and Lotus timezone names, and timezone abbreviations.

Parameters

string $timezone

Some timezone alias.

Returns

string —

The Olson timezone name, or the original value, if no alias found.

setTimezone()

setTimezone(string  $timezone) : \Horde_Date

Converts this object to a different timezone.

Parameters

string $timezone

The new timezone.

Throws

\Horde_Date_Exception

Returns

\Horde_Date

This object.

setDefaultFormat()

setDefaultFormat(string  $format) 

Sets the default date format used in __toString()

Parameters

string $format

dayOfWeek()

dayOfWeek() : integer

Returns the day of the week (0 = Sunday, 6 = Saturday) of this date.

Returns

integer —

The day of the week.

dayOfYear()

dayOfYear() : integer

Returns the day number of the year (1 to 365/366).

Returns

integer —

The day of the year.

weekOfMonth()

weekOfMonth() : integer

Returns the week of the month.

Returns

integer —

The week number.

weekOfYear()

weekOfYear() : integer

Returns the week of the year, first Monday is first day of first week.

Returns

integer —

The week number.

weeksInYear()

weeksInYear(integer  $year) : integer

Returns the number of weeks in the given year (52 or 53).

Parameters

integer $year

The year to count the number of weeks in.

Returns

integer —

$numWeeks The number of weeks in $year.

setNthWeekday()

setNthWeekday(integer  $weekday, integer  $nth = 1) 

Sets the date of this object to the $nth weekday of $weekday.

Parameters

integer $weekday

The day of the week (0 = Sunday, etc).

integer $nth

The $nth $weekday to set to (defaults to 1). Negative values count from end of the month (@since Horde_Date 2.1.0).

isValid()

isValid() : boolean

Is the date currently represented by this object a valid date?

Returns

boolean —

Validity, counting leap years, etc.

compareDate()

compareDate(mixed  $other) : integer

Compares this date to another date object to see which one is greater (later). Assumes that the dates are in the same timezone.

Parameters

mixed $other

The date to compare to.

Returns

integer —

== 0 if they are on the same date

= 1 if $this is greater (later) <= -1 if $other is greater (later)

after()

after(mixed  $other) : boolean

Returns whether this date is after the other.

Parameters

mixed $other

The date to compare to.

Returns

boolean —

True if this date is after the other.

before()

before(mixed  $other) : boolean

Returns whether this date is before the other.

Parameters

mixed $other

The date to compare to.

Returns

boolean —

True if this date is before the other.

equals()

equals(mixed  $other) : boolean

Returns whether this date is the same like the other.

Parameters

mixed $other

The date to compare to.

Returns

boolean —

True if this date is the same like the other.

compareTime()

compareTime(mixed  $other) : integer

Compares this to another date object by time, to see which one is greater (later). Assumes that the dates are in the same timezone.

Parameters

mixed $other

The date to compare to.

Returns

integer —

== 0 if they are at the same time

= 1 if $this is greater (later) <= -1 if $other is greater (later)

compareDateTime()

compareDateTime(mixed  $other) : integer

Compares this to another date object, including times, to see which one is greater (later). Assumes that the dates are in the same timezone.

Parameters

mixed $other

The date to compare to.

Returns

integer —

== 0 if they are equal

= 1 if $this is greater (later) <= -1 if $other is greater (later)

diff()

diff(\Horde_Date  $other) : integer

Returns number of days between this date and another.

Parameters

\Horde_Date $other

The other day to diff with.

Returns

integer —

The absolute number of days between the two dates.

tzOffset()

tzOffset(boolean  $colon = true) : string

Returns the time offset for local time zone.

Parameters

boolean $colon

Place a colon between hours and minutes?

Returns

string —

Timezone offset as a string in the format +HH:MM.

timestamp()

timestamp() : integer

Returns the unix timestamp representation of this date.

Returns

integer —

A unix timestamp.

datestamp()

datestamp() : integer

Returns the unix timestamp representation of this date, 12:00am.

Returns

integer —

A unix timestamp.

dateString()

dateString() : string

Formats date and time to be passed around as a short url parameter.

Returns

string —

Date and time.

toJson()

toJson() : string

Formats date and time to the ISO format used by JSON.

Returns

string —

Date and time.

toiCalendar()

toiCalendar(boolean  $floating = false) : string

Formats date and time to the RFC 2445 iCalendar DATE-TIME format.

Parameters

boolean $floating

Whether to return a floating date-time (without time zone information).

Returns

string —

Date and time.

format()

format(string  $format) : string

Formats time using the specifiers available in date() or in the DateTime class' format() method.

To format in languages other than English, use strftime() instead.

Parameters

string $format

Returns

string —

Formatted time.

strftime()

strftime(  $format) : string

Formats date and time using strftime() format.

Parameters

$format

Returns

string —

strftime() formatted date and time.

_regexCallback()

_regexCallback(  $reg) : string

Callback used to replace a strtime pattern

Parameters

$reg

Returns

string —

Replacement string.

_strftime()

_strftime(  $format) : string

Formats date and time using a limited set of the strftime() format.

Parameters

$format

Returns

string —

strftime() formatted date and time.

_correct()

_correct(integer  $mask = self::MASK_ALLPARTS, integer  $down = false) 

Corrects any over- or underflows in any of the date's members.

Parameters

integer $mask

We may not want to correct some overflows.

integer $down

Whether to correct the date up or down.

_correctMonth()

_correctMonth() 

Corrects the current month.

This cannot be done in _correct() because that would also trigger a correction of the day, which would result in an infinite loop.

_initializeFromArgs()

_initializeFromArgs(  $args) 

Handles args in order: year month day hour min sec tz

Parameters

$args

_initializeFromArray()

_initializeFromArray(  $date) 

Parameters

$date

_initializeFromObject()

_initializeFromObject(  $date) 

Parameters

$date

_initializeTimezone()

_initializeTimezone(  $timezone) 

Parameters

$timezone