|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Andegna\Ethiopian; |
|
4
|
|
|
|
|
5
|
|
|
use Andegna\Converter\ToJdnConverter; |
|
6
|
|
|
|
|
7
|
|
|
trait DateTimeProcessor |
|
8
|
|
|
{ |
|
9
|
|
|
public function add($interval) |
|
10
|
|
|
{ |
|
11
|
|
|
return new DateTime($this->dateTime->add($interval)); |
|
|
|
|
|
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function sub($interval) |
|
15
|
|
|
{ |
|
16
|
|
|
return new DateTime($this->dateTime->sub($interval)); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function modify($modify) |
|
20
|
|
|
{ |
|
21
|
|
|
return new DateTime($this->dateTime->modify($modify)); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function diff($datetime, $absolute = false) |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->dateTime->diff($datetime, $absolute); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function setDate($year, $month, $day) |
|
30
|
|
|
{ |
|
31
|
|
|
$jdn = (new ToJdnConverter($day, $month, $year))->getJdn(); |
|
32
|
|
|
|
|
33
|
|
|
$gregorian = jdtogregorian($jdn); |
|
34
|
|
|
|
|
35
|
|
|
list( |
|
36
|
|
|
$month, |
|
37
|
|
|
$day, |
|
38
|
|
|
$year) = explode('/', $gregorian); |
|
39
|
|
|
|
|
40
|
|
|
return new DateTime( |
|
41
|
|
|
$this->dateTime->setDate((int) $year, (int) $month, (int) $day) |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function setTime($hour, $minute, $second = 0) |
|
46
|
|
|
{ |
|
47
|
|
|
return new DateTime( |
|
48
|
|
|
$this->dateTime->setTime($hour, $minute, $second) |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function setTimestamp($unixtimestamp) |
|
53
|
|
|
{ |
|
54
|
|
|
return new DateTime( |
|
55
|
|
|
$this->dateTime->setTimestamp($unixtimestamp) |
|
56
|
|
|
); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function setTimezone($timezone) |
|
60
|
|
|
{ |
|
61
|
|
|
return new DateTime( |
|
62
|
|
|
$this->dateTime->setTimezone($timezone) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function getOffset() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->dateTime->getOffset(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getTimezone() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->dateTime->getTimezone(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function __wakeup() |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->dateTime->__wakeup(); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: