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
Afficher le fichier Open project: Webiny/Framework Class Usage Examples

Protected Properties

Свойство Type Description
$value DateTime | null

Méthodes publiques

Méthode 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

Méthode 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 méthode

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 méthode

To string implementation.
public __toString ( ) : mixed
Résultat mixed

createFromFormat() public static méthode

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.
Résultat DateTimeObject

diff() public méthode

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?
Résultat 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 méthode

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

getDate() public méthode

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

getDay() public méthode

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

getHours() public méthode

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

getMeridiem() public méthode

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

getMinutes() public méthode

Get minutes based on current date.
public getMinutes ( ) : string
Résultat string Minutes based on current date

getMongoDate() public méthode

Get MongoDate object
public getMongoDate ( ) : MongoDB\BSON\UTCDatetime
Résultat MongoDB\BSON\UTCDatetime

getMonth() public méthode

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

getOffset() public méthode

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

getSeconds() public méthode

Get seconds based on current date.
public getSeconds ( ) : string
Résultat string Seconds based on current date.

getTime() public méthode

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

getTimeAgo() public méthode

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.
Résultat string String describing the passed time. Example "4 hours ago".

getTimestamp() public méthode

Get UNIX timestamp based on current date.
public getTimestamp ( ) : integer
Résultat integer UNIX timestamp based on current date

getTimezone() public méthode

Get the name of current timezone.
public getTimezone ( ) : string
Résultat string The name of current timezone.

getWeek() public méthode

Get week number based on current date.
public getWeek ( ) : integer
Résultat integer Wek number based on current date.

getYear() public méthode

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

setFormat() public méthode

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 méthode

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 méthode

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.
Résultat mixed

Property Details

$value protected_oe property

protected DateTime|null $value
Résultat DateTime | null