PHP Class Webiny\Component\StdLib\StdObject\DateTimeObject\DateTimeObject

Class that enables you to work with dates and time much easier.
Inheritance: extends Webiny\Component\StdLib\StdObject\AbstractStdObject, use trait ValidatorTrait, use trait ManipulatorTrait
Datei anzeigen Open project: Webiny/Framework Class Usage Examples

Protected Properties

Property Type Description
$value DateTime | null

Public Methods

Method Description
__construct ( string | integer $time = "now", null | string $timezone = null ) Constructor.
__toString ( ) : mixed To string implementation.
createFromFormat ( string | integer $time, null | string $format = null ) : DateTimeObject Create a DateTimeObject from the given $time and $format.
diff ( integer | string | DateTime | DateTimeObject $time, boolean $absolute = false ) : ArrayObject
format ( string $format ) : string Return date in the given format.
getDate ( null | string $format = null ) : string Get date in full date format.
getDay ( null | string $format = null ) : string Get day based on current date.
getHours ( null | string $format = null ) : string Get hours based on current date.
getMeridiem ( null | string $format = null ) : string Get meridiem (am, pm) based on current date.
getMinutes ( ) : string Get minutes based on current date.
getMongoDate ( ) : MongoDB\BSON\UTCDatetime Get MongoDate object
getMonth ( null | string $format = null ) : string Get month based on current date.
getOffset ( ) : integer Get the offset from current timezone to the UTC timezone in seconds.
getSeconds ( ) : string Get seconds based on current date.
getTime ( null | string $format = null ) : string Return time based on current date.
getTimeAgo ( null $from = null ) : string Calculates the time passed between current date and $form (default: now).
getTimestamp ( ) : integer Get UNIX timestamp based on current date.
getTimezone ( ) : string Get the name of current timezone.
getWeek ( ) : integer Get week number based on current date.
getYear ( null | string $format = null ) : string Get year based on current date.
setFormat ( string $format ) Set the date format.
setTimezone ( string | DateTimeZone $timezone ) Set a new timezone for current date object.
val ( null $value = null ) : mixed Return, or update, current standard objects value.

Private Methods

Method Description
buildFormatterList ( ) Reformats self::$formatters from array to ArrayObject.
createTimezone ( string | null $timezone = null ) : DateTimeZone Create a DateTimeZone object for the given $timeZone.
getDateElement ( string $dateElement, null | string $format = null ) : string Returns defined $dateElement in defined $format.
getDateObject ( ) : DateTime | null Returns current \DateTime object.
getFormatFor ( string $dateElement ) : mixed Returns format for defined $dateElement.
parseDateTimeFormat ( ) This function parses the format provided by Config and sets the default formatting for getting date information like day, month, year, etc.
validateFormatFor ( string $dateElement, string $format ) : mixed Checks if $format is a valid format for $dateElement.

Method Details

__construct() public method

Set standard object value.
public __construct ( string | integer $time = "now", null | string $timezone = null )
$time string | integer A date/time string. List of available formats is explained here http://www.php.net/manual/en/datetime.formats.php
$timezone null | string Timezone in which you want to set the date. Here is a list of valid timezones: http://php.net/manual/en/timezones.php

__toString() public method

To string implementation.
public __toString ( ) : mixed
return mixed

createFromFormat() public static method

Create a DateTimeObject from the given $time and $format.
public static createFromFormat ( string | integer $time, null | string $format = null ) : DateTimeObject
$time string | integer Timestamp.
$format null | string Format in which the current timestamp is defined.
return DateTimeObject

diff() public method

public diff ( integer | string | DateTime | DateTimeObject $time, boolean $absolute = false ) : ArrayObject
$time integer | string | DateTime | DateTimeObject Date to compare to.
$absolute boolean Should the interval be forced to be positive?
return Webiny\Component\StdLib\StdObject\ArrayObject\ArrayObject Instance of ArrayObject containing time units (d,m,y,h,i,s) for keys and amounts for their values.

format() public method

Return date in the given format.
public format ( string $format ) : string
$format string A valid date format.
return string A string containing the date in the given $format.

getDate() public method

Get date in full date format.
public getDate ( null | string $format = null ) : string
$format null | string A valid date format.
return string Date in full date format like ISO 8691 or RFC 2822.

getDay() public method

Get day based on current date.
public getDay ( null | string $format = null ) : string
$format null | string A valid day format.
return string Day based on current date.

getHours() public method

Get hours based on current date.
public getHours ( null | string $format = null ) : string
$format null | string A valid hour format.
return string Hours based on current date.

getMeridiem() public method

Get meridiem (am, pm) based on current date.
public getMeridiem ( null | string $format = null ) : string
$format null | string A valid meridiem format.
return string Meridiem (am, pm) based on current date.

getMinutes() public method

Get minutes based on current date.
public getMinutes ( ) : string
return string Minutes based on current date

getMongoDate() public method

Get MongoDate object
public getMongoDate ( ) : MongoDB\BSON\UTCDatetime
return MongoDB\BSON\UTCDatetime

getMonth() public method

Get month based on current date.
public getMonth ( null | string $format = null ) : string
$format null | string A valid month format.
return string Month based on current date.

getOffset() public method

Get the offset from current timezone to the UTC timezone in seconds.
public getOffset ( ) : integer
return integer The offset from current timezone to UTC in seconds.

getSeconds() public method

Get seconds based on current date.
public getSeconds ( ) : string
return string Seconds based on current date.

getTime() public method

Return time based on current date.
public getTime ( null | string $format = null ) : string
$format null | string A valid time format.
return string Time based on current date.

getTimeAgo() public method

The output is formatted in plain words, like "4 hours ago".
public getTimeAgo ( null $from = null ) : string
$from null Timestamp from where to calculate the offset. Default is now.
return string String describing the passed time. Example "4 hours ago".

getTimestamp() public method

Get UNIX timestamp based on current date.
public getTimestamp ( ) : integer
return integer UNIX timestamp based on current date

getTimezone() public method

Get the name of current timezone.
public getTimezone ( ) : string
return string The name of current timezone.

getWeek() public method

Get week number based on current date.
public getWeek ( ) : integer
return integer Wek number based on current date.

getYear() public method

Get year based on current date.
public getYear ( null | string $format = null ) : string
$format null | string A valid year format.
return string Year based on current date.

setFormat() public method

Set the date format.
public setFormat ( string $format )
$format string Date format. These are the valid options: http://php.net/manual/en/function.date.php

setTimezone() public method

NOTE: The current timestamp will be recalculated with the offset of current timezone and the new defined one.
public setTimezone ( string | DateTimeZone $timezone )
$timezone string | DateTimeZone Timezone to which you wish to offset. You can either pass \DateTimeZone object or a valid timezone string. For timezone string formats visit: http://php.net/manual/en/timezones.php

val() public method

Return, or update, current standard objects value.
public val ( null $value = null ) : mixed
$value null If $value is set, value is updated and DateTimeObject is returned.
return mixed

Property Details

$value protected_oe property

protected DateTime|null $value
return DateTime | null