Interface DateTime
Interface for ICanBoogie's mutable and immutable date time classes.
-
ICanBoogie\DateTime
implements
DateTimeInterface
Methods summary
public static
from( mixed $source
, mixed $timezone
= null )
: ICanBoogie\DateTime
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
none( DateTimeZone|string $timezone
= 'utc' )
: ICanBoogie\DateTime
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
now( void )
: ICanBoogie\DateTime
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
right_now( void )
: ICanBoogie\DateTime
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
change( array $options
, boolean $cascade
= false )
: ICanBoogie\DateTime
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
with( array $options
, boolean $cascade
= false )
: ICanBoogie\DateTime
Returns a new instance with changes properties.
Returns a new instance with changes properties.
Parameters
Returns
public
localize( string $locale
= 'en' )
: mixed
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
DB
: string
DB (example: 2013-02-03 20:59:03)
DB (example: 2013-02-03 20:59:03)
'Y-m-d H:i:s'
NUMBER
: string
Number (example: 20130203205903)
Number (example: 20130203205903)
'YmdHis'
DATE
: string
Date (example: 2013-02-03)
Date (example: 2013-02-03)
'Y-m-d'