ICanBoogie
  • Documentation
  • API Reference
  • DateTime 2.0.x
Namespaces
  • ICanBoogie
    • DateTime
Classes
  • DateTimeLocalizer
  • ImmutableDateTime
  • MutableDateTime
  • TimeZone
  • TimeZoneLocation
Interfaces
  • DateTime

Interface DateTime

Interface for ICanBoogie's mutable and immutable date time classes.

ICanBoogie\DateTime implements DateTimeInterface

Direct known implementers

ICanBoogie\ImmutableDateTime, ICanBoogie\MutableDateTime

Namespace: ICanBoogie
Located at DateTime.php

Methods summary

public static from( mixed $source, mixed $timezone = null ) : ICanBoogie\DateTime

Creates a ICanBoogie\DateTime instance from a source.

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

ICanBoogie\DateTime
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;                      // true
$d->timezone->name;                // "UTC"

$d = DateTime::none('Asia/Tokyo');
$d->is_empty;                      // true
$d->timezone->name;                // "Asia/Tokio"

Parameters

$timezone

The time zone in which the empty date is created. Defaults to "UTC".

Returns

ICanBoogie\DateTime
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

ICanBoogie\DateTime
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

ICanBoogie\DateTime
public modify( string $modify ) : ICanBoogie\DateTime

Alters the timestamp.

Alters the timestamp.

Parameters

$modify

Returns

ICanBoogie\DateTime
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

ICanBoogie\DateTime
$this
public with( array $options, boolean $cascade = false ) : ICanBoogie\DateTime

Returns a new instance with changes properties.

Returns a new instance with changes properties.

Parameters

$options
$cascade

Returns

ICanBoogie\DateTime
public localize( string $locale = 'en' ) : mixed

Returns a localized instance.

Returns a localized instance.

Parameters

$locale

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'
TIME : string

Time (example: 20:59:03)

Time (example: 20:59:03)

'H:i:s'
DateTime 2.0.x – Check on GitHub – API documentation generated by ApiGen