Overview

Namespaces

  • Jyxo
    • Beholder
      • TestCase
    • Gettext
      • Parser
    • Input
      • Chain
      • Filter
      • Validator
    • Mail
      • Email
        • Attachment
      • Parser
      • Sender
    • Rpc
      • Json
      • Xml
    • Shell
    • Spl
    • Svn
    • Time
    • Webdav
  • PHP

Classes

  • Composer
  • Time
  • Util

Exceptions

  • ComposerException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated

Class Time

Class for working with date and time. Internally uses a \DateTime object. Initialization is possible using almost any date/time format (unix timestamp, SQL form, ...).

Requires the Gettext PHP extension or any other implementation of the _(string) translation function.

Jyxo\Time\Time implements Serializable
Namespace: Jyxo\Time
Category: Jyxo
Package: Jyxo\Time
Copyright: Copyright (c) 2005-2011 Jyxo, s.r.o.
License: https://github.com/jyxo/php/blob/master/license.txt
Author: Jaroslav Hanslík
Author: Jan Kolibač
Author: Roman Řáha
Author: Martin Šamšula
Author: Ondřej Nešpor
Located at Time/Time.php
Methods summary
public
# __construct( string|integer|Jyxo\Time\Time|DateTime $time, string|DateTimeZone $timeZone = null )

Constructor.

Constructor.

Creates an instance and initializes the internal date/time representation.

Parameters

$time
string|integer|Jyxo\Time\Time|DateTime
Date/time definition
$timeZone
string|DateTimeZone
Time zone definition

Throws

InvalidArgumentException
If an incompatible date/time format or time zone definition was provided
protected DateTimeZone
# createTimeZone( string|DateTimeZone $definition )

Creates a \DateTimeZone object from a time zone definition

Creates a \DateTimeZone object from a time zone definition

Parameters

$definition
string|DateTimeZone
Time zone definition

Returns

DateTimeZone

Throws

InvalidArgumentException
If an invalid time zone definition was provided
public static Jyxo\Time\Time
# get( string|integer|Jyxo\Time\Time|DateTime $time, string|DateTimeZone $timeZone = null )

Helper function for creating an instance with the given date/time.

Helper function for creating an instance with the given date/time.

Useful for one-time usage.

Parameters

$time
string|integer|Jyxo\Time\Time|DateTime
Date/time definition
$timeZone
string|DateTimeZone
Time zone definition

Returns

Jyxo\Time\Time
public static Jyxo\Time\Time
# now( )

Returns an instance with the current date/time.

Returns an instance with the current date/time.

Returns

Jyxo\Time\Time
public static Jyxo\Time\Time
# createFromFormat( string $format, string $time )

Creates an instance using a date/time definition in the given format.

Creates an instance using a date/time definition in the given format.

Parameters

$format
string
Date/time format
$time
string
Date/time definition

Returns

Jyxo\Time\Time
public mixed
# __get( string $name )

Returns date/time in the requested format.

Returns date/time in the requested format.

Parameters

$name
string
Format name

Returns

mixed

Throws

InvalidArgumentException
If an unknown format is requested
public mixed
# __call( string $method, array $args )

Calls a method directly on the internal \DateTime object.

Calls a method directly on the internal \DateTime object.

Parameters

$method
string
Method name
$args
array
Method arguments

Returns

mixed
public string
# __toString( )

Returns date/time in the unix timestamp format.

Returns date/time in the unix timestamp format.

Returns

string
Returns empty string if the stored date/time has no valid UT representation
public DateTimeZone
# getTimeZone( )

Returns the actual time zone.

Returns the actual time zone.

Returns

DateTimeZone
public Jyxo\Time\Time
# setTimeZone( string|DateTimeZone $timeZone )

Sets a new time zone.

Sets a new time zone.

Parameters

$timeZone
string|DateTimeZone
The new time zone

Returns

Jyxo\Time\Time
protected
# setTemporaryTimeZone( string|DateTimeZone $timeZone )

Sets a time zone temporarily.

Sets a time zone temporarily.

Parameters

$timeZone
string|DateTimeZone
Temporary time zone definition

Throws

InvalidArgumentException
If an invalid time zone definition was provided
protected Jyxo\Time\Time
# revertOriginalTimeZone( )

Reverts the original time zone.

Reverts the original time zone.

Returns

Jyxo\Time\Time

Throws

InvalidArgumentException
If there is no time zone to return to
public string
# format( string $format, string|DateTimeZone $timeZone = null )

Returns date/time in the given format with months and days translated.

Returns date/time in the given format with months and days translated.

Parameters

$format
string
Requested format
$timeZone
string|DateTimeZone
Result time zone definition

Returns

string
public string
# formatExtended( string $dateFormat = 'j. F Y', string $timeFormat = 'G:i', string|DateTimeZone $timeZone = null )

Returns date/time in the form of:

Returns date/time in the form of:

Today at 10:00 Yesterday at 10:00 Friday at 10:00 21. March 2009 at 10:00

Parameters

$dateFormat
string
Date format
$timeFormat
string
Time format
$timeZone
string|DateTimeZone
Result time zone definition

Returns

string
public string
# formatAsInterval( boolean $useTense = true, string|DateTimeZone $timeZone = null )

Function for formatting time differences into human readable forms.

Function for formatting time differences into human readable forms.

$t < 10 seconds = Now 10 seconds <= $t < 60 seconds 1 minute <= $t < 1 hour 1 hour <= $t < 24 hours 1 day <= $t < 7 days 1 week <= $t < 4 weeks 1 month <= $t < 12 months 1 year <= $t < n years

Parameters

$useTense
boolean
Defines if declension should be used
$timeZone
string|DateTimeZone
Result time zone definition

Returns

string
public Jyxo\Time\Time
# plus( integer|string $interval )

Returns a new date/time object and adds with the given interval added.

Returns a new date/time object and adds with the given interval added.

Parameters

$interval
integer|string
Number of seconds or a string compatible with the strtotime() function

Returns

Jyxo\Time\Time
public Jyxo\Time\Time
# minus( integer|string $interval )

Returns a new date/time object and adds with the given interval subtracted.

Returns a new date/time object and adds with the given interval subtracted.

Parameters

$interval
integer|string
Number of seconds or a string compatible with the strtotime() function

Returns

Jyxo\Time\Time
public boolean
# hasHappened( )

Checks if the date/time already happened.

Checks if the date/time already happened.

Compares the internal date/time with the current local time of the appropriate time zone.

Returns

boolean
public Jyxo\Time\Time
# truncate( string $unit )

Returns a new instance with date/time truncated to the given unit.

Returns a new instance with date/time truncated to the given unit.

Parameters

$unit
string
Unit to truncate the date/time to

Returns

Jyxo\Time\Time

Throws

InvalidArgumentException
If an invalid unit is provided
public string
# serialize( )

Object serialization.

Object serialization.

Returns

string

Implementation of

Serializable::serialize
public
# unserialize( string $serialized )

Object deserialization.

Object deserialization.

Parameters

$serialized
string
Serialized data

Throws

InvalidArgumentException
On deserialization error

Implementation of

Serializable::unserialize
Constants summary
string SECOND 'second'
#

Second.

Second.

string MINUTE 'minute'
#

Minute.

Minute.

string HOUR 'hour'
#

Hour.

Hour.

string DAY 'day'
#

Day.

Day.

string WEEK 'week'
#

Week.

Week.

string MONTH 'month'
#

Month.

Month.

string YEAR 'year'
#

Year.

Year.

integer INTERVAL_SECOND 1
#

Number of seconds in a second.

Number of seconds in a second.

integer INTERVAL_MINUTE 60
#

Number of seconds in a minute.

Number of seconds in a minute.

integer INTERVAL_HOUR 3600
#

Number of seconds in an hour.

Number of seconds in an hour.

integer INTERVAL_DAY 86400
#

Number of seconds in a day.

Number of seconds in a day.

integer INTERVAL_WEEK 604800
#

Number of seconds in a week.

Number of seconds in a week.

integer INTERVAL_MONTH 2592000
#

Number of seconds in a month.

Number of seconds in a month.

integer INTERVAL_YEAR 31536000
#

Number of seconds in a year.

Number of seconds in a year.

Jyxo PHP Library API documentation generated by ApiGen 2.3.0