ICanBoogie/DateTime 2.0.x
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • DateTime

Classes

  • DateTimeLocalizer
  • ImmutableDateTime
  • MutableDateTime
  • TimeZone
  • TimeZoneLocation

Interfaces

  • DateTime
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie;

/**
 * Interface for ICanBoogie's mutable and immutable date time classes.
 */
interface DateTime extends \DateTimeInterface
{
    /**
     * DB (example: 2013-02-03 20:59:03)
     *
     * @var string
     */
    const DB = 'Y-m-d H:i:s';

    /**
     * Number (example: 20130203205903)
     *
     * @var string
     */
    const NUMBER = 'YmdHis';

    /**
     * Date (example: 2013-02-03)
     *
     * @var string
     */
    const DATE = 'Y-m-d';

    /**
     * Time (example: 20:59:03)
     *
     * @var string
     */
    const TIME = 'H:i:s';

    /**
     * Creates a {@link DateTime} instance from a source.
     *
     * <pre>
     * <?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');
     * </pre>
     *
     * @param mixed $source
     * @param mixed $timezone The time zone to use to create the time. The value is ignored if the
     * source is an instance of {@link \DateTime}.
     *
     * @return static
     */
    static public function from($source, $timezone = null);

    /**
     * Returns an instance representing an empty date ("0000-00-00").
     *
     * <pre>
     * <?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"
     * </pre>
     *
     * @param \DateTimeZone|string $timezone The time zone in which the empty date is created.
     * Defaults to "UTC".
     *
     * @return static
     */
    static public function none($timezone = 'utc');

    /**
     * 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.
     *
     * @return static
     */
    static public function now();

    /**
     * Returns an instance with the current local time and the local time zone.
     *
     * **Note:** Subsequent calls may return different times.
     *
     * @return static
     */
    static public function right_now();

    /**
     * Alters the timestamp.
     *
     * @param string $modify
     *
     * @return static
     */
    public function modify($modify);

    /**
     * Modifies the properties of the instance according to the options.
     *
     * The following properties can be updated: {@link $year}, {@link $month}, {@link $day},
     * {@link $hour}, {@link $minute} and {@link $second}.
     *
     * Note: Values exceeding ranges are added to their parent values.
     *
     * <pre>
     * <?php
     *
     * use ICanBoogie\ImmutableDateTime as DateTime;
     *
     * $time = new DateTime('now');
     * $time->change([ 'year' => 2000, 'second' => 0 ]);
     * </pre>
     *
     * @param array $options
     * @param bool $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.
     *
     * @return $this
     */
    public function change(array $options, $cascade = false);

    /**
     * Returns a new instance with changes properties.
     *
     * @param array $options
     * @param bool $cascade
     *
     * @return DateTime
     */
    public function with(array $options, $cascade = false);

    /**
     * Returns a localized instance.
     *
     * @param string $locale
     *
     * @return mixed
     *
     * @throws \LogicException if the instance cannot be localized.
     */
    public function localize($locale = 'en');
}
ICanBoogie/DateTime 2.0.x API documentation generated by ApiGen