PHP Class Habari\DateTime

Inheritance: extends DateTime
Show file Open project: habari/system Class Usage Examples

Public Methods

Method Description
__get ( $property ) Magic method to get magic ponies.
__static ( ) Set default timezone to system default on init.
__toString ( ) : string Magic method called when this object is cast to string. Returns the unix timestamp of this object.
create ( string $time = null, string $timezone = null ) : DateTime Helper function to create a DateTime object for the given time and timezone. If no time is given, defaults to 'now'. If no timezone given defaults to timezone set in {@link set_default_timezone()}
date_create ( $time = null, $timezone = null ) This function should not be used. Use ::create() instead
difference ( mixed $start_date, mixed $end_date ) : array Returns an array representing the difference between two times by interval.
format ( string $format = null ) : string Returns date formatted according to given format.
friendly ( integer $precision = 7, boolean $include_suffix = true, $comparison_date = 'now' ) : string Returns a friendlier string version of the time, ie: 3 days, 1 hour, and 5 minutes ago
fuzzy ( $comparison_date = 'now' ) Similar to friendly(), but much more.
get ( $format = null )
get_default_date_format ( ) : string Return the default date format, as set in the Options table
get_default_datetime_format ( ) : string Get the default date/time format set.
get_default_time_format ( ) : string Return the default time format, as set in the Options table
get_default_timezone ( ) Get the timezone for Habari and PHP.
get_last_exception ( ) Get the last exception thrown when trying to create
get_timezone ( ) : DateTimeZone Get the timezone identifier that is set for this datetime object.
getdate ( ) : array Returns an associative array containing the date information for this DateTime object, as per {@link http://php.net/getdate getdate()}
modify ( string $args ) : DateTime Alters the timestamp
out ( string $format = null ) Echos date formatted according to given format.
set_date ( integer $year, integer $month, integer $day ) : DateTime Set the date of this object
set_default_date_format ( string $format ) Set default date format. The format is the same as the internal php {@link http://ca.php.net/date date() function}.
set_default_datetime_format ( string $format ) Set default date/time format. The format is the same as the internal php {@link http://ca.php.net/date date() function}.
set_default_time_format ( string $format ) Set default time format. The format is the same as the internal php {@link http://ca.php.net/date date() function}.
set_default_timezone ( string $timezone ) Sets the timezone for Habari and PHP.
set_isodate ( integer $year, $week, integer $day = null ) : DateTime Sets the ISO date
set_time ( integer $hour, integer $minute, integer $second = null ) : DateTime Set the time of this object
set_timezone ( mixed $timezone ) : DateTime Set the timezone for this datetime object. Can be either string timezone identifier, or DateTimeZone object.
text_format ( string $format ) : string Returns date components inserted into a string

Private Methods

Method Description
text_format_callback ( array $matches ) : string Callback method for supplying replacements for HabariDatTime::text_format()

Method Details

__get() public method

.. properties, I mean.
public __get ( $property )

__static() public static method

Set default timezone to system default on init.
public static __static ( )

__toString() public method

Magic method called when this object is cast to string. Returns the unix timestamp of this object.
public __toString ( ) : string
return string The unix timestamp

create() public static method

Helper function to create a DateTime object for the given time and timezone. If no time is given, defaults to 'now'. If no timezone given defaults to timezone set in {@link set_default_timezone()}
See also: DateTime::__construct()
public static create ( string $time = null, string $timezone = null ) : DateTime
$time string String in a format accepted by {@link http://ca.php.net/strtotime strtotime()}, defaults to "now".
$timezone string A timezone name, not an abbreviation.
return DateTime

date_create() public static method

This function should not be used. Use ::create() instead
Deprecation:
public static date_create ( $time = null, $timezone = null )

difference() public static method

print_r( DateTime::difference( 'now', 'January 1, 2010' ) ); output (past): Array ( [invert] => [y] => 0 [m] => 9 [w] => 3 [d] => 5 [h] => 22 [i] => 33 [s] => 5 ) print_r( DateTime::difference( 'now', 'January 1, 2011' ) ); output (future): Array ( [invert] => 1 [y] => 0 [m] => 2 [w] => 0 [d] => 3 [h] => 5 [i] => 33 [s] => 11 ) If 'invert' is true, the time is in the future (ie: x from now). If it is false, the time is in the past (ie: x ago). For more information, see PHP's DateInterval class, which this and friendly() attempt to emulate for < PHP 5.3
public static difference ( mixed $start_date, mixed $end_date ) : array
$start_date mixed The start date, as a HDT object or any format accepted by DateTime::create().
$end_date mixed The end date, as a HDT object or any format accepted by DateTime::create().
return array Array of each interval and whether the interval is inverted or not.

format() public method

Returns date formatted according to given format.
See also: DateTime::format()
public format ( string $format = null ) : string
$format string Format accepted by {@link http://php.net/date date()}.
return string The formatted date, false on failure.

friendly() public method

Returns a friendlier string version of the time, ie: 3 days, 1 hour, and 5 minutes ago
public friendly ( integer $precision = 7, boolean $include_suffix = true, $comparison_date = 'now' ) : string
$precision integer Only display x intervals. Note that this does not round, it only limits the display length.
$include_suffix boolean Include the 'ago' or 'from now' suffix?
return string Time passed in the specified units.

fuzzy() public method

.. fuzzy. Returns a very short version of the difference in time between now and the current HDT object.
public fuzzy ( $comparison_date = 'now' )

get() public method

See also: format()
public get ( $format = null )

get_default_date_format() public static method

Return the default date format, as set in the Options table
public static get_default_date_format ( ) : string
return string The default date format

get_default_datetime_format() public static method

Get the default date/time format set.
See also: set_default_datetime_format()
public static get_default_datetime_format ( ) : string
return string The date format set.

get_default_time_format() public static method

Return the default time format, as set in the Options table
public static get_default_time_format ( ) : string
return string The default time format

get_default_timezone() public static method

Defaults to system timezone if not set.
See also: set_default_timezone()
public static get_default_timezone ( )

get_last_exception() public static method

Get the last exception thrown when trying to create
public static get_last_exception ( )

get_timezone() public method

Get the timezone identifier that is set for this datetime object.
public get_timezone ( ) : DateTimeZone
return DateTimeZone The timezone object.

getdate() public method

Returns an associative array containing the date information for this DateTime object, as per {@link http://php.net/getdate getdate()}
public getdate ( ) : array
return array Associative array containing the date information

modify() public method

Alters the timestamp
public modify ( string $args ) : DateTime
$args string A format accepted by {@link http://php.net/strtotime strtotime()}..
return DateTime $this object.

out() public method

Echos date formatted according to given format.
See also: format()
public out ( string $format = null )
$format string Format accepted by {@link http://php.net/date date()}.

set_date() public method

Set the date of this object
See also: DateTime::setDate()
public set_date ( integer $year, integer $month, integer $day ) : DateTime
$year integer Year of the date
$month integer Month of the date
$day integer Day of the date
return DateTime

set_default_date_format() public static method

Set default date format. The format is the same as the internal php {@link http://ca.php.net/date date() function}.
public static set_default_date_format ( string $format )
$format string The date format.

set_default_datetime_format() public static method

Set default date/time format. The format is the same as the internal php {@link http://ca.php.net/date date() function}.
public static set_default_datetime_format ( string $format )
$format string The date format.

set_default_time_format() public static method

Set default time format. The format is the same as the internal php {@link http://ca.php.net/date date() function}.
public static set_default_time_format ( string $format )
$format string The time format.

set_default_timezone() public static method

Sets the timezone for Habari and PHP.
public static set_default_timezone ( string $timezone )
$timezone string A timezone name, not an abbreviation, for example 'America/New York'

set_isodate() public method

Sets the ISO date
See also: DateTime::setISODate()
public set_isodate ( integer $year, $week, integer $day = null ) : DateTime
$year integer Year of the date
$day integer Day of the date
return DateTime

set_time() public method

Set the time of this object
See also: DateTime::setTime()
public set_time ( integer $hour, integer $minute, integer $second = null ) : DateTime
$hour integer Hour of the time
$minute integer Minute of the time
$second integer Second of the time
return DateTime

set_timezone() public method

Set the timezone for this datetime object. Can be either string timezone identifier, or DateTimeZone object.
See also: DateTime::setTimezone()
public set_timezone ( mixed $timezone ) : DateTime
$timezone mixed The timezone to use.
return DateTime $this object.

text_format() public method

Example: echo DateTime::create('2010-01-01')->text_format('The year was {Y}.'); Expected output: The year was 2010.
public text_format ( string $format ) : string
$format string A string with single-character date format codes {@link http://php.net/date date()} surrounded by braces
return string The string with date components inserted