| 1 | <?php |
||
| 8 | class Date implements JsonSerializable |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @const string Default datetime format. |
||
| 12 | */ |
||
| 13 | const DEFAULT_DATETIME_FORMAT = DateTime::ISO8601; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @const string Default date format. |
||
| 17 | */ |
||
| 18 | const DEFAULT_DATE_FORMAT = 'Y-m-d'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var string The stored value. |
||
| 22 | */ |
||
| 23 | public $value; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Constructor. |
||
| 27 | * |
||
| 28 | * @param string $value |
||
| 29 | */ |
||
| 30 | 3 | public function __construct($value) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * Creates an instance using the specified datetime format. |
||
| 37 | * |
||
| 38 | * @param DateTime $value |
||
| 39 | * @param string $format |
||
| 40 | * |
||
| 41 | * @return self |
||
| 42 | */ |
||
| 43 | 3 | public static function fromDateTime( |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Creates an instance using the specified date format. |
||
| 52 | * |
||
| 53 | * @param DateTime $value |
||
| 54 | * @param string $format |
||
| 55 | * |
||
| 56 | * @return self |
||
| 57 | */ |
||
| 58 | 1 | public static function fromDate( |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Converts to DateTime type. |
||
| 67 | * |
||
| 68 | * @param string $format |
||
| 69 | * |
||
| 70 | * @return DateTime |
||
| 71 | */ |
||
| 72 | 2 | public function toDateTime($format = self::DEFAULT_DATETIME_FORMAT) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @inheritdoc |
||
| 79 | */ |
||
| 80 | 1 | public function jsonSerialize() |
|
| 84 | } |
||
| 85 |