-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCDateTime.php
More file actions
66 lines (55 loc) · 1.43 KB
/
Copy pathCDateTime.php
File metadata and controls
66 lines (55 loc) · 1.43 KB
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
<?php
/**
* @author Dmitriy Tyurin <fobia3d@gmail.com>
* @copyright Copyright (c) 2014 Dmitriy Tyurin
*/
/**
* DateTime with serialization and timestamp support for PHP 5.2.
*/
class CDateTime extends \DateTime
{
/** minute in seconds */
const MINUTE = 60;
/** hour in seconds */
const HOUR = 3600;
/** day in seconds */
const DAY = 86400;
/** week in seconds */
const WEEK = 604800;
/** average month in seconds */
const MONTH = 2629800;
/** average year in seconds */
const YEAR = 31557600;
const ATOM = 'Y-m-d H:i:s';
/**
* DateTime object factory.
* @param string|int|\DateTime
* @return DateTime
*/
public static function from($time)
{
if ($time instanceof \DateTime) {
return new self($time->format('Y-m-d H:i:s'), $time->getTimezone());
} elseif (is_numeric($time)) {
if ($time <= self::YEAR) {
$time += time();
}
return new static(date('Y-m-d H:i:s', $time));
} else { // textual or NULL
return new static($time);
}
}
public function toString()
{
return $this->format('Y-m-d H:i:s');
}
public function modifyClone($modify = '')
{
$dolly = clone $this;
return $modify ? $dolly->modify($modify) : $dolly;
}
public function __toString()
{
return $this->toString();
}
}