Class Time

Summary

Fully Qualified Name: CodeIgniter\I18n\Time
Extends: DateTime

Description

Class Time

A localized date/time package inspired by Nesbot/Carbon and CakePHP/Chronos.

Requires the intl PHP extension.

Methods

Name Description Defined By
__construct() Time constructor. Time
__get() Allow for property-type access to any getX method. Time
__isset() Allow for property-type checking to any getX method. Time
__toString() Outputs a short format version of the datetime. Time
addDays() Returns a new Time instance with $days added to the time. Time
addHours() Returns a new Time instance with $hours added to the time. Time
addMinutes() Returns a new Time instance with $minutes added to the time. Time
addMonths() Returns a new Time instance with $months added to the time. Time
addSeconds() Returns a new Time instance with $seconds added to the time. Time
addYears() Returns a new Time instance with $years added to the time. Time
create() Returns a new instance with the date time values individually set. Time
createFromDate() Returns a new instance based on the year, month and day. If any of those three are left empty, will default to the current value. Time
createFromFormat() Provides a replacement for DateTime's own createFromFormat function, that provides more flexible timeZone handling Time
createFromTime() Returns a new instance with the date set to today, and the time set to the values passed in. Time
createFromTimestamp() Returns a new instance with the datetime set based on the provided UNIX timestamp. Time
difference() Time
equals() Determines if the datetime passed in is equal to the current instance. Time
getAge() Returns the age in years from the "current" date and 'now' Time
getCalendar() Returns the IntlCalendar object used for this object, taking into account the locale, date, etc. Time
getDay() Return the localized day of the month. Time
getDayOfWeek() Return the index of the day of the week Time
getDayOfYear() Return the index of the day of the year Time
getDst() Are we in daylight savings time currently? Time
getHour() Return the localized hour (in 24-hour format). Time
getLocal() Returns boolean whether the passed timezone is the same as the local timezone. Time
getMinute() Return the localized minutes in the hour. Time
getMonth() Returns the localized Month Time
getQuarter() Returns the number of the current quarter for the year. Time
getSecond() Return the localized seconds Time
getTimezoneName() Returns the name of the current timezone. Time
getUTCObject() Returns a Time instance with the timezone converted to UTC. Time
getUtc() Returns boolean whether object is in UTC. Time
getWeekOfMonth() Return the index of the week in the month Time
getWeekOfYear() Return the index of the week in the year Time
getYear() Returns the localized Year Time
hasTestNow() Returns whether we have a testNow instance saved. Time
humanize() Returns a text string that is easily readable that describes how long ago, or how long from now, a date is, like: Time
instance() Takes an instance of DateTime and returns an instance of Time with it's same values. Time
isAfter() Determines if the current instance's time is after $testTime, after converting in UTC. Time
isBefore() Determines if the current instance's time is before $testTime, after converting to UTC. Time
now() Returns a new Time instance with the timezone set. Time
parse() Returns a new Time instance while parsing a datetime string. Time
sameAs() Ensures that the times are identical, taking timezone into account. Time
setDay() Sets the day of the month. Time
setHour() Sets the hour of the day (24 hour cycle) Time
setMinute() Sets the minute of the hour Time
setMonth() Sets the month of the year. Time
setSecond() Sets the second of the minute. Time
setTestNow() Creates an instance of Time that will be returned during testing when calling 'Time::now' instead of the current time. Time
setTimestamp() Returns a new instance with the date set to the new timestamp. Time
setTimezone() Returns a new instance with the revised timezone. Time
setYear() Sets the current year for this instance. Time
subDays() Returns a new Time instance with $days subtracted from the time. Time
subHours() Returns a new Time instance with $hours subtracted from the time. Time
subMinutes() Returns a new Time instance with $minutes subtracted from the time. Time
subMonths() Returns a new Time instance with $months subtracted from the time. Time
subSeconds() Returns a new Time instance with $seconds subtracted from the time. Time
subYears() Returns a new Time instance with $hours subtracted from the time. Time
toDateString() Returns a localized version of the date in Y-m-d format. Time
toDateTime() Converts the current instance to a mutable DateTime object. Time
toDateTimeString() Returns the localized value of the date in the format 'Y-m-d H:i:s' Time
toFormattedDateString() Returns a localized version of the date in nicer date format: Time
toLocalizedString() Returns the localized value of this instance in $format. Time
toTimeString() Returns a localized version of the time in nicer date format: Time
today() Return a new time with the time set to midnight. Time
tomorrow() Returns an instance set to midnight tomorrow morning. Time
yesterday() Returns an instance set to midnight yesterday morning. Time

Method Details

__construct()

Time constructor.

Parameter Name Type Description
$time string|null
$timezone null
$locale string|null

Returns:

__get()

Allow for property-type access to any getX method.

..

Note that we cannot use this for any of our setX methods, as they return new Time objects, but the __set ignores return values. See http://php.net/manual/en/language.oop5.overloading.php

Parameter Name Type Description
$name
$name

Returns: mixed

__isset()

Allow for property-type checking to any getX method.

..

Parameter Name Type Description
$name
$name

Returns: bool

__toString()

Outputs a short format version of the datetime.

Returns: string

addDays()

Returns a new Time instance with $days added to the time.

Parameter Name Type Description
$days int

Returns: static

addHours()

Returns a new Time instance with $hours added to the time.

Parameter Name Type Description
$hours int

Returns: static

addMinutes()

Returns a new Time instance with $minutes added to the time.

Parameter Name Type Description
$minutes int

Returns: static

addMonths()

Returns a new Time instance with $months added to the time.

Parameter Name Type Description
$months int

Returns: static

addSeconds()

Returns a new Time instance with $seconds added to the time.

Parameter Name Type Description
$seconds int

Returns: static

addYears()

Returns a new Time instance with $years added to the time.

Parameter Name Type Description
$years int

Returns: static

create()

Returns a new instance with the date time values individually set.

Parameter Name Type Description
$year int|null
$month int|null
$day int|null
$hour int|null
$minutes int|null
$seconds int|null
$timezone null
$locale string|null

Returns: \CodeIgniter\I18n\Time

createFromDate()

Returns a new instance based on the year, month and day. If any of those three are left empty, will default to the current value.

Parameter Name Type Description
$year int|null
$month int|null
$day int|null
$timezone null
$locale string

Returns: \CodeIgniter\I18n\Time

createFromFormat()

Provides a replacement for DateTime's own createFromFormat function, that provides more flexible timeZone handling

Parameter Name Type Description
$format string
$datetime string
$timeZone \DateTimeZone|string

Returns: \CodeIgniter\I18n\Time

createFromTime()

Returns a new instance with the date set to today, and the time set to the values passed in.

Parameter Name Type Description
$hour int|null
$minutes int|null
$seconds int|null
$timezone null
$locale string|null

Returns: \CodeIgniter\I18n\Time

createFromTimestamp()

Returns a new instance with the datetime set based on the provided UNIX timestamp.

Parameter Name Type Description
$timestamp int
$timeZone \DateTimeZone
$locale string|null

Returns: \CodeIgniter\I18n\Time

difference()

Parameter Name Type Description
$testTime
$timezone string|null
$testTime

Returns: \CodeIgniter\I18n\TimeDifference

equals()

Determines if the datetime passed in is equal to the current instance.

Equal in this case means that they represent the same moment in time, and are not required to be in the same timezone, as both times are converted to UTC and compared that way.

Parameter Name Type Description
$testTime \Time|\DateTime|string
$timezone string|null

Returns: bool

getAge()

Returns the age in years from the "current" date and 'now'

Returns:

getCalendar()

Returns the IntlCalendar object used for this object, taking into account the locale, date, etc.

Primarily used internally to provide the difference and comparison functions, but available for public consumption if they need it.

Returns: \IntlCalendar

getDay()

Return the localized day of the month.

Returns: string

getDayOfWeek()

Return the index of the day of the week

Returns: string

getDayOfYear()

Return the index of the day of the year

Returns: string

getDst()

Are we in daylight savings time currently?

Returns: bool

getHour()

Return the localized hour (in 24-hour format).

Returns: string

getLocal()

Returns boolean whether the passed timezone is the same as the local timezone.

Returns: bool

getMinute()

Return the localized minutes in the hour.

Returns: string

getMonth()

Returns the localized Month

Returns: string

getQuarter()

Returns the number of the current quarter for the year.

Returns: string

getSecond()

Return the localized seconds

Returns: string

getTimezoneName()

Returns the name of the current timezone.

Returns: string

getUTCObject()

Returns a Time instance with the timezone converted to UTC.

Parameter Name Type Description
$time
$timezone string|null
$time

Returns: \DateTime|static

getUtc()

Returns boolean whether object is in UTC.

Returns: bool

getWeekOfMonth()

Return the index of the week in the month

Returns: string

getWeekOfYear()

Return the index of the week in the year

Returns: string

getYear()

Returns the localized Year

Returns: string

hasTestNow()

Returns whether we have a testNow instance saved.

Returns: bool

humanize()

Returns a text string that is easily readable that describes how long ago, or how long from now, a date is, like:

Returns: mixed

instance()

Takes an instance of DateTime and returns an instance of Time with it's same values.

Parameter Name Type Description
$dateTime \DateTime
$locale string|null

Returns: \CodeIgniter\I18n\Time

isAfter()

Determines if the current instance's time is after $testTime, after converting in UTC.

Parameter Name Type Description
$testTime
$timezone string|null
$testTime

Returns: bool

isBefore()

Determines if the current instance's time is before $testTime, after converting to UTC.

Parameter Name Type Description
$testTime
$timezone string|null
$testTime

Returns: bool

now()

Returns a new Time instance with the timezone set.

Parameter Name Type Description
$timezone string|\DateTimeZone|null
$locale string|null

Returns: \CodeIgniter\I18n\Time

parse()

Returns a new Time instance while parsing a datetime string.

Example: $time = Time::parse('first day of December 2008');

Parameter Name Type Description
$datetime string
$timezone string|null
$locale string|null

Returns: \CodeIgniter\I18n\Time

sameAs()

Ensures that the times are identical, taking timezone into account.

Parameter Name Type Description
$testTime \Time|\DateTime|string
$timezone string|null

Returns: bool

setDay()

Sets the day of the month.

Parameter Name Type Description
$value
$value

Returns: \CodeIgniter\I18n\Time

setHour()

Sets the hour of the day (24 hour cycle)

Parameter Name Type Description
$value
$value

Returns: \CodeIgniter\I18n\Time

setMinute()

Sets the minute of the hour

Parameter Name Type Description
$value
$value

Returns: \CodeIgniter\I18n\Time

setMonth()

Sets the month of the year.

Parameter Name Type Description
$value
$value

Returns: \CodeIgniter\I18n\Time

setSecond()

Sets the second of the minute.

Parameter Name Type Description
$value
$value

Returns: \CodeIgniter\I18n\Time

setTestNow()

Creates an instance of Time that will be returned during testing when calling 'Time::now' instead of the current time.

Parameter Name Type Description
$datetime \CodeIgniter\I18n\Time|string
$timezone null
$locale string|null

Returns:

setTimestamp()

Returns a new instance with the date set to the new timestamp.

Parameter Name Type Description
$timestamp int

Returns: \CodeIgniter\I18n\Time

setTimezone()

Returns a new instance with the revised timezone.

Parameter Name Type Description
$timezone \DateTimeZone

Returns: \CodeIgniter\I18n\Time

setYear()

Sets the current year for this instance.

Parameter Name Type Description
$value
$value

Returns: \CodeIgniter\I18n\Time

subDays()

Returns a new Time instance with $days subtracted from the time.

Parameter Name Type Description
$days int

Returns: static

subHours()

Returns a new Time instance with $hours subtracted from the time.

Parameter Name Type Description
$hours int

Returns: static

subMinutes()

Returns a new Time instance with $minutes subtracted from the time.

Parameter Name Type Description
$minutes int

Returns: static

subMonths()

Returns a new Time instance with $months subtracted from the time.

Parameter Name Type Description
$months int

Returns: static

subSeconds()

Returns a new Time instance with $seconds subtracted from the time.

Parameter Name Type Description
$seconds int

Returns: static

subYears()

Returns a new Time instance with $hours subtracted from the time.

Parameter Name Type Description
$years int

Returns: static

toDateString()

Returns a localized version of the date in Y-m-d format.

Returns: string

toDateTime()

Converts the current instance to a mutable DateTime object.

Returns: \DateTime

toDateTimeString()

Returns the localized value of the date in the format 'Y-m-d H:i:s'

Returns:

toFormattedDateString()

Returns a localized version of the date in nicer date format:

i.e. Apr 1, 2017

Returns: string

toLocalizedString()

Returns the localized value of this instance in $format.

Parameter Name Type Description
$format string|null

Returns: string|bool

toTimeString()

Returns a localized version of the time in nicer date format:

i.e. 13:20:33

Returns: string

today()

Return a new time with the time set to midnight.

Parameter Name Type Description
$timezone null
$locale string|null

Returns: \CodeIgniter\I18n\Time

tomorrow()

Returns an instance set to midnight tomorrow morning.

Parameter Name Type Description
$timezone null
$locale string|null

Returns: \CodeIgniter\I18n\Time

yesterday()

Returns an instance set to midnight yesterday morning.

Parameter Name Type Description
$timezone null
$locale string|null

Returns: \CodeIgniter\I18n\Time

Top