PHP Класс Jyxo\Time\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.
Автор: Jaroslav Hanslík
Автор: Jan Kolibač
Автор: Roman Řáha
Автор: Martin Šamšula
Автор: Ondřej Nešpor
Наследование: implements Serializable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__call ( string $method, array $args ) : mixed Calls a method directly on the internal \DateTime object.
__construct ( string | integer | Time | DateTime $time, string | DateTimeZone $timeZone = null ) Constructor.
__get ( string $name ) : mixed Returns date/time in the requested format.
__toString ( ) : string Returns date/time in the unix timestamp format.
createFromFormat ( string $format, string $time ) : self Creates an instance using a date/time definition in the given format.
format ( string $format, string | DateTimeZone $timeZone = null ) : string Returns date/time in the given format with months and days translated.
formatAsInterval ( boolean $useTense = true, string | DateTimeZone $timeZone = null ) : string Function for formatting time differences into human readable forms.
formatExtended ( string $dateFormat = 'j. F Y', string $timeFormat = 'G:i', string | DateTimeZone $timeZone = null ) : string Returns date/time in the form of:
get ( string | integer | Time | DateTime $time, string | DateTimeZone $timeZone = null ) : self Helper function for creating an instance with the given date/time.
getTimeZone ( ) : DateTimeZone Returns the actual time zone.
hasHappened ( ) : boolean Checks if the date/time already happened.
minus ( integer | string $interval ) : self Returns a new date/time object and adds with the given interval subtracted.
now ( ) : self Returns an instance with the current date/time.
plus ( integer | string $interval ) : self Returns a new date/time object and adds with the given interval added.
serialize ( ) : string Object serialization.
setTimeZone ( string | DateTimeZone $timeZone ) : self Sets a new time zone.
truncate ( string $unit ) : self Returns a new instance with date/time truncated to the given unit.
unserialize ( string $serialized ) Object deserialization.

Защищенные методы

Метод Описание
createTimeZone ( string | DateTimeZone $definition ) : DateTimeZone Creates a \DateTimeZone object from a time zone definition
revertOriginalTimeZone ( ) : self Reverts the original time zone.
setTemporaryTimeZone ( string | DateTimeZone $timeZone ) Sets a time zone temporarily.

Описание методов

__call() публичный Метод

Calls a method directly on the internal \DateTime object.
public __call ( string $method, array $args ) : mixed
$method string Method name
$args array Method arguments
Результат mixed

__construct() публичный Метод

Creates an instance and initializes the internal date/time representation.
public __construct ( string | integer | Time | DateTime $time, string | DateTimeZone $timeZone = null )
$time string | integer | Time | DateTime Date/time definition
$timeZone string | DateTimeZone Time zone definition

__get() публичный Метод

Returns date/time in the requested format.
public __get ( string $name ) : mixed
$name string Format name
Результат mixed

__toString() публичный Метод

Returns date/time in the unix timestamp format.
public __toString ( ) : string
Результат string Returns empty string if the stored date/time has no valid UT representation

createFromFormat() публичный статический Метод

Creates an instance using a date/time definition in the given format.
public static createFromFormat ( string $format, string $time ) : self
$format string Date/time format
$time string Date/time definition
Результат self

createTimeZone() защищенный Метод

Creates a \DateTimeZone object from a time zone definition
protected createTimeZone ( string | DateTimeZone $definition ) : DateTimeZone
$definition string | DateTimeZone Time zone definition
Результат DateTimeZone

format() публичный Метод

Returns date/time in the given format with months and days translated.
public format ( string $format, string | DateTimeZone $timeZone = null ) : string
$format string Requested format
$timeZone string | DateTimeZone Result time zone definition
Результат string

formatAsInterval() публичный Метод

$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
public formatAsInterval ( boolean $useTense = true, string | DateTimeZone $timeZone = null ) : string
$useTense boolean Defines if declension should be used
$timeZone string | DateTimeZone Result time zone definition
Результат string

formatExtended() публичный Метод

Today at 10:00 Yesterday at 10:00 Friday at 10:00 21. March 2009 at 10:00
public formatExtended ( string $dateFormat = 'j. F Y', string $timeFormat = 'G:i', string | DateTimeZone $timeZone = null ) : string
$dateFormat string Date format
$timeFormat string Time format
$timeZone string | DateTimeZone Result time zone definition
Результат string

get() публичный статический Метод

Useful for one-time usage.
public static get ( string | integer | Time | DateTime $time, string | DateTimeZone $timeZone = null ) : self
$time string | integer | Time | DateTime Date/time definition
$timeZone string | DateTimeZone Time zone definition
Результат self

getTimeZone() публичный Метод

Returns the actual time zone.
public getTimeZone ( ) : DateTimeZone
Результат DateTimeZone

hasHappened() публичный Метод

Compares the internal date/time with the current local time of the appropriate time zone.
public hasHappened ( ) : boolean
Результат boolean

minus() публичный Метод

Returns a new date/time object and adds with the given interval subtracted.
public minus ( integer | string $interval ) : self
$interval integer | string Number of seconds or a string compatible with the strtotime() function
Результат self

now() публичный статический Метод

Returns an instance with the current date/time.
public static now ( ) : self
Результат self

plus() публичный Метод

Returns a new date/time object and adds with the given interval added.
public plus ( integer | string $interval ) : self
$interval integer | string Number of seconds or a string compatible with the strtotime() function
Результат self

revertOriginalTimeZone() защищенный Метод

Reverts the original time zone.
protected revertOriginalTimeZone ( ) : self
Результат self

serialize() публичный Метод

Object serialization.
public serialize ( ) : string
Результат string

setTemporaryTimeZone() защищенный Метод

Sets a time zone temporarily.
protected setTemporaryTimeZone ( string | DateTimeZone $timeZone )
$timeZone string | DateTimeZone Temporary time zone definition

setTimeZone() публичный Метод

Sets a new time zone.
public setTimeZone ( string | DateTimeZone $timeZone ) : self
$timeZone string | DateTimeZone The new time zone
Результат self

truncate() публичный Метод

Returns a new instance with date/time truncated to the given unit.
public truncate ( string $unit ) : self
$unit string Unit to truncate the date/time to
Результат self

unserialize() публичный Метод

Object deserialization.
public unserialize ( string $serialized )
$serialized string Serialized data