PHP Class Horde_Date, horde

Mostrar archivo Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_corrections array Map of required correction masks.
$_defaultFormat string Default format for __toString()
$_defaultSpecs string Default specs that are always supported.
$_formatCache
$_hour integer Hour
$_mday integer Day
$_min integer Minute
$_month integer Month
$_sec integer Second
$_supportedSpecs string Internally supported strftime() specifiers.
$_timezone string String representation of the date's timezone.
$_timezoneAbbreviations array These aliases map timezone abbreviations to those understood by PHP.
$_timezoneAliases array These aliases map Windows, Lotus, and other Timezone IDs to those understood by PHP.
$_timezoneIdentifiers array A list of (Olson) timezone identifiers understood by PHP.
$_year integer Year

Public Methods

Method Description
__construct ( $date = null, $timezone = null ) Builds a new date object. If $date contains date parts, use them to initialize the object.
__get ( string $name ) : integer | string Getter for the date and time properties.
__isset ( string $name ) : boolen Returns whether a date or time property exists.
__set ( string $name, integer | string $value ) Setter for the date and time properties.
__toString ( ) : string Returns a simple string representation of the date object
add ( $factor ) Adds a number of seconds or units to this date, returning a new Date object.
after ( mixed $other ) : boolean Returns whether this date is after the other.
before ( mixed $other ) : boolean Returns whether this date is before the other.
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.
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.
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.
dateString ( ) : string Formats date and time to be passed around as a short url parameter.
datestamp ( ) : integer Returns the unix timestamp representation of this date, 12:00am.
dayOfWeek ( ) : integer Returns the day of the week (0 = Sunday, 6 = Saturday) of this date.
dayOfYear ( ) : integer Returns the day number of the year (1 to 365/366).
diff ( Horde_Date $other ) : integer Returns number of days between this date and another.
equals ( mixed $other ) : boolean Returns whether this date is the same like the other.
format ( string $format ) : string Formats time using the specifiers available in date() or in the DateTime class' format() method.
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.
getTimezoneAlias ( string $timezone ) : string Returns the normalized (Olson) timezone name of a timezone alias.
isValid ( ) : boolean Is the date currently represented by this object a valid date?
setDefaultFormat ( string $format ) Sets the default date format used in __toString()
setNthWeekday ( integer $weekday, integer $nth = 1 ) Sets the date of this object to the $nth weekday of $weekday.
setTimezone ( string $timezone ) : Horde_Date Converts this object to a different timezone.
strftime ( $format ) : string Formats date and time using strftime() format.
sub ( $factor ) Subtracts a number of seconds or units from this date, returning a new Horde_Date object.
timestamp ( ) : integer Returns the unix timestamp representation of this date.
toDateTime ( ) : DateTime Returns a DateTime object representing this object.
toDays ( ) : integer Converts a date in the proleptic Gregorian calendar to the no of days since 24th November, 4714 B.C.
toJson ( ) : string Formats date and time to the ISO format used by JSON.
toiCalendar ( boolean $floating = false ) : string Formats date and time to the RFC 2445 iCalendar DATE-TIME format.
tzOffset ( boolean $colon = true ) : string Returns the time offset for local time zone.
weekOfMonth ( ) : integer Returns the week of the month.
weekOfYear ( ) : integer Returns the week of the year, first Monday is first day of first week.
weeksInYear ( integer $year ) : integer Returns the number of weeks in the given year (52 or 53).

Protected Methods

Method Description
_correct ( integer $mask = self::MASK_ALLPARTS, integer $down = false ) Corrects any over- or underflows in any of the date's members.
_correctMonth ( ) Corrects the current month.
_initializeFromArgs ( $args ) Handles args in order: year month day hour min sec tz
_initializeFromArray ( $date )
_initializeFromObject ( $date )
_initializeTimezone ( $timezone )
_regexCallback ( $reg ) : string Callback used to replace a strtime pattern
_strftime ( $format ) : string Formats date and time using a limited set of the strftime() format.

Method Details

__construct() public method

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.
public __construct ( $date = null, $timezone = null )

__get() public method

Getter for the date and time properties.
public __get ( string $name ) : integer | string
$name string One of 'year', 'month', 'mday', 'hour', 'min', 'sec' or 'timezone' (since Horde_Date 2.0.0).
return integer | string The property value, or null if not set.

__isset() public method

Returns whether a date or time property exists.
public __isset ( string $name ) : boolen
$name string One of 'year', 'month', 'mday', 'hour', 'min' or 'sec'.
return boolen True if the property exists and is set.

__set() public method

Setter for the date and time properties.
public __set ( string $name, integer | string $value )
$name string One of 'year', 'month', 'mday', 'hour', 'min', 'sec' or 'timezone' (since Horde_Date 2.0.0).
$value integer | string The property value.

__toString() public method

Returns a simple string representation of the date object
public __toString ( ) : string
return string This object converted to a string.

_correct() protected method

Corrects any over- or underflows in any of the date's members.
protected _correct ( integer $mask = self::MASK_ALLPARTS, integer $down = false )
$mask integer We may not want to correct some overflows.
$down integer Whether to correct the date up or down.

_correctMonth() protected method

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

_initializeFromArgs() protected method

Handles args in order: year month day hour min sec tz
protected _initializeFromArgs ( $args )

_initializeFromArray() protected method

protected _initializeFromArray ( $date )

_initializeFromObject() protected method

protected _initializeFromObject ( $date )

_initializeTimezone() protected method

protected _initializeTimezone ( $timezone )

_regexCallback() protected method

Callback used to replace a strtime pattern
protected _regexCallback ( $reg ) : string
return string Replacement string.

_strftime() protected method

Formats date and time using a limited set of the strftime() format.
protected _strftime ( $format ) : string
return string strftime() formatted date and time.

add() public method

Adds a number of seconds or units to this date, returning a new Date object.
public add ( $factor )

after() public method

Returns whether this date is after the other.
public after ( mixed $other ) : boolean
$other mixed The date to compare to.
return boolean True if this date is after the other.

before() public method

Returns whether this date is before the other.
public before ( mixed $other ) : boolean
$other mixed The date to compare to.
return boolean True if this date is before the other.

compareDate() public method

Compares this date to another date object to see which one is greater (later). Assumes that the dates are in the same timezone.
public compareDate ( mixed $other ) : integer
$other mixed The date to compare to.
return integer == 0 if they are on the same date >= 1 if $this is greater (later) <= -1 if $other is greater (later)

compareDateTime() public method

Compares this to another date object, including times, to see which one is greater (later). Assumes that the dates are in the same timezone.
public compareDateTime ( mixed $other ) : integer
$other mixed The date to compare to.
return integer == 0 if they are equal >= 1 if $this is greater (later) <= -1 if $other is greater (later)

compareTime() public method

Compares this to another date object by time, to see which one is greater (later). Assumes that the dates are in the same timezone.
public compareTime ( mixed $other ) : integer
$other mixed The date to compare to.
return integer == 0 if they are at the same time >= 1 if $this is greater (later) <= -1 if $other is greater (later)

dateString() public method

Formats date and time to be passed around as a short url parameter.
public dateString ( ) : string
return string Date and time.

datestamp() public method

Returns the unix timestamp representation of this date, 12:00am.
public datestamp ( ) : integer
return integer A unix timestamp.

dayOfWeek() public method

Returns the day of the week (0 = Sunday, 6 = Saturday) of this date.
public dayOfWeek ( ) : integer
return integer The day of the week.

dayOfYear() public method

Returns the day number of the year (1 to 365/366).
public dayOfYear ( ) : integer
return integer The day of the year.

diff() public method

Returns number of days between this date and another.
public diff ( Horde_Date $other ) : integer
$other Horde_Date The other day to diff with.
return integer The absolute number of days between the two dates.

equals() public method

Returns whether this date is the same like the other.
public equals ( mixed $other ) : boolean
$other mixed The date to compare to.
return boolean True if this date is the same like the other.

format() public method

To format in languages other than English, use strftime() instead.
public format ( string $format ) : string
$format string
return string Formatted time.

fromDays() public static method

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
Author: Monte Ohrt ([email protected])
Author: Pierre-Alain Joye ([email protected])
Author: Daniel Convissor ([email protected])
Author: C.A. Woodcock ([email protected])
public static fromDays ( integer $days ) : Horde_Date
$days integer the number of days since 24th November, 4714 B.C.
return Horde_Date A Horde_Date object representing the date.

getTimezoneAlias() public static method

We currently support Windows and Lotus timezone names, and timezone abbreviations.
public static getTimezoneAlias ( string $timezone ) : string
$timezone string Some timezone alias.
return string The Olson timezone name, or the original value, if no alias found.

isValid() public method

Is the date currently represented by this object a valid date?
public isValid ( ) : boolean
return boolean Validity, counting leap years, etc.

setDefaultFormat() public method

Sets the default date format used in __toString()
public setDefaultFormat ( string $format )
$format string

setNthWeekday() public method

Sets the date of this object to the $nth weekday of $weekday.
public setNthWeekday ( integer $weekday, integer $nth = 1 )
$weekday integer The day of the week (0 = Sunday, etc).
$nth integer The $nth $weekday to set to (defaults to 1). Negative values count from end of the month (@since Horde_Date 2.1.0).

setTimezone() public method

Converts this object to a different timezone.
public setTimezone ( string $timezone ) : Horde_Date
$timezone string The new timezone.
return Horde_Date This object.

strftime() public method

Formats date and time using strftime() format.
public strftime ( $format ) : string
return string strftime() formatted date and time.

sub() public method

Subtracts a number of seconds or units from this date, returning a new Horde_Date object.
public sub ( $factor )

timestamp() public method

Returns the unix timestamp representation of this date.
public timestamp ( ) : integer
return integer A unix timestamp.

toDateTime() public method

Returns a DateTime object representing this object.
public toDateTime ( ) : DateTime
return DateTime

toDays() public method

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
Author: Monte Ohrt ([email protected])
Author: Pierre-Alain Joye ([email protected])
Author: Daniel Convissor ([email protected])
Author: C.A. Woodcock ([email protected])
public toDays ( ) : integer
return integer The number of days since 24th November, 4714 B.C.

toJson() public method

Formats date and time to the ISO format used by JSON.
public toJson ( ) : string
return string Date and time.

toiCalendar() public method

Formats date and time to the RFC 2445 iCalendar DATE-TIME format.
public toiCalendar ( boolean $floating = false ) : string
$floating boolean Whether to return a floating date-time (without time zone information).
return string Date and time.

tzOffset() public method

Returns the time offset for local time zone.
public tzOffset ( boolean $colon = true ) : string
$colon boolean Place a colon between hours and minutes?
return string Timezone offset as a string in the format +HH:MM.

weekOfMonth() public method

Returns the week of the month.
public weekOfMonth ( ) : integer
return integer The week number.

weekOfYear() public method

Returns the week of the year, first Monday is first day of first week.
public weekOfYear ( ) : integer
return integer The week number.

weeksInYear() public static method

Returns the number of weeks in the given year (52 or 53).
public static weeksInYear ( integer $year ) : integer
$year integer The year to count the number of weeks in.
return integer $numWeeks The number of weeks in $year.

Property Details

$_corrections protected_oe static_oe property

Map of required correction masks.
See also: __set()
protected static array $_corrections
return array

$_defaultFormat protected_oe property

Default format for __toString()
protected string $_defaultFormat
return string

$_defaultSpecs protected_oe static_oe property

Default specs that are always supported.
protected static string $_defaultSpecs
return string

$_formatCache protected_oe property

protected $_formatCache

$_hour protected_oe property

Hour
protected int $_hour
return integer

$_mday protected_oe property

Day
protected int $_mday
return integer

$_min protected_oe property

Minute
protected int $_min
return integer

$_month protected_oe property

Month
protected int $_month
return integer

$_sec protected_oe property

Second
protected int $_sec
return integer

$_supportedSpecs protected_oe static_oe property

Internally supported strftime() specifiers.
protected static string $_supportedSpecs
return string

$_timezone protected_oe property

String representation of the date's timezone.
protected string $_timezone
return string

$_timezoneAbbreviations protected_oe static_oe property

These aliases map timezone abbreviations to those understood by PHP.
See also: getTimezoneAlias()
protected static array $_timezoneAbbreviations
return array

$_timezoneAliases protected_oe static_oe property

These aliases map Windows, Lotus, and other Timezone IDs to those understood by PHP.
protected static array $_timezoneAliases
return array

$_timezoneIdentifiers protected_oe static_oe property

A list of (Olson) timezone identifiers understood by PHP.
See also: getTimezoneAlias()
protected static array $_timezoneIdentifiers
return array

$_year protected_oe property

Year
protected int $_year
return integer