Interface DateTime
Interface for ICanBoogie's mutable and immutable date time classes.
-
ICanBoogie\DateTime
implements
DateTimeInterface
Methods summary
public static
ICanBoogie\DateTime
|
#
from( mixed $source, mixed $timezone = null )
Creates a ICanBoogie\DateTime instance from a source.
<?php
use ICanBoogie\ImmutableDateTime as DateTime;
DateTime::from(new \DateTime('2001-01-01 01:01:01', new \DateTimeZone('Europe/Paris')));
DateTime::from('2001-01-01 01:01:01', 'Europe/Paris');
DateTime::from('now');
Parameters
- $source
- $timezone
The time zone to use to create the time. The value is ignored if the
source is an instance of \DateTime.
Returns
|
public static
ICanBoogie\DateTime
|
#
none( DateTimeZone|string $timezone = 'utc' )
Returns an instance representing an empty date ("0000-00-00").
Returns an instance representing an empty date ("0000-00-00").
<?php
use ICanBoogie\ImmutableDateTime as DateTime;
$d = DateTime::none();
$d->is_empty;
$d->timezone->name;
$d = DateTime::none('Asia/Tokyo');
$d->is_empty;
$d->timezone->name;
Parameters
- $timezone
The time zone in which the empty date is created.
Defaults to "UTC".
Returns
|
public static
ICanBoogie\DateTime
|
#
now( )
Returns an instance with the current local time and the local time zone.
Returns an instance with the current local time and the local time zone.
Note: Subsequent calls return equal times, event if they are minutes apart. now
actually refers to the REQUEST_TIME or, if it is now available, to the first time
the method was invoked.
Returns
|
public static
ICanBoogie\DateTime
|
#
right_now( )
Returns an instance with the current local time and the local time zone.
Returns an instance with the current local time and the local time zone.
Note: Subsequent calls may return different times.
Returns
|
public
ICanBoogie\DateTime
|
#
modify( string $modify )
Alters the timestamp.
Parameters
Returns
|
public
ICanBoogie\DateTime
|
#
change( array $options, boolean $cascade = false )
Modifies the properties of the instance according to the options.
Modifies the properties of the instance according to the options.
The following properties can be updated: $year, $month, $day,
$hour, $minute and $second.
Note: Values exceeding ranges are added to their parent values.
<?php
use ICanBoogie\ImmutableDateTime as DateTime;
$time = new DateTime('now');
$time->change([ 'year' => 2000, 'second' => 0 ]);
Parameters
- $options
- $cascade
If true , time options (hour , minute , second ) reset
cascading, so if only the hour is passed, then minute and second is set to 0. If the hour
and minute is passed, then second is set to 0.
Returns
|
public
ICanBoogie\DateTime
|
#
with( array $options, boolean $cascade = false )
Returns a new instance with changes properties.
Returns a new instance with changes properties.
Parameters
Returns
|
public
mixed
|
#
localize( string $locale = 'en' )
Returns a localized instance.
Returns a localized instance.
Parameters
Returns
mixed
Throws
LogicException if the instance cannot be localized.
|
Methods inherited from DateTimeInterface
__wakeup()
,
diff()
,
format()
,
getOffset()
,
getTimestamp()
,
getTimezone()
Constants summary
string |
DB
DB (example: 2013-02-03 20:59:03)
DB (example: 2013-02-03 20:59:03)
|
|
string |
NUMBER
Number (example: 20130203205903)
Number (example: 20130203205903)
|
|
string |
DATE
Date (example: 2013-02-03)
Date (example: 2013-02-03)
|
|
string |
TIME
|
|