1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Popy\Calendar\Converter; |
4
|
|
|
|
5
|
|
|
use DateTimeInterface; |
6
|
|
|
use Popy\Calendar\ValueObject\DateRepresentationInterface; |
7
|
|
|
|
8
|
|
|
class Conversion |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Date to convert. |
12
|
|
|
* |
13
|
|
|
* @var DateRepresentationInterface |
14
|
|
|
*/ |
15
|
|
|
protected $from; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Converted date (being built). Holds the date being built during a |
19
|
|
|
* conversion from unix time, and an eventually completed copy of the |
20
|
|
|
* source date. |
21
|
|
|
* |
22
|
|
|
* @var DateRepresentationInterface|null |
23
|
|
|
*/ |
24
|
|
|
protected $to; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Remaining/Accumulated unix time during conversion from/to timestamp. |
28
|
|
|
* |
29
|
|
|
* @var integer|null |
30
|
|
|
*/ |
31
|
|
|
protected $unixTime; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Remaining/Accumulated unix microtime during conversion from/to timestamp. |
35
|
|
|
* |
36
|
|
|
* @var integer|null |
37
|
|
|
*/ |
38
|
|
|
protected $unixMicroTime; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Class constructor. |
42
|
|
|
* |
43
|
|
|
* @param DateRepresentationInterface $from |
44
|
|
|
* @param DateRepresentationInterface|null $to |
45
|
|
|
*/ |
46
|
|
|
public function __construct(DateRepresentationInterface $from, DateRepresentationInterface $to = null) |
47
|
|
|
{ |
48
|
|
|
$this->from = $from; |
49
|
|
|
$this->to = $to; |
50
|
|
|
$this->unixTime = $from->getUnixTime(); |
51
|
|
|
$this->unixMicroTime = $from->getUnixMicroTime(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Gets the Date to convert. |
56
|
|
|
* |
57
|
|
|
* @return DateRepresentationInterface |
58
|
|
|
*/ |
59
|
|
|
public function getFrom() |
60
|
|
|
{ |
61
|
|
|
return $this->from; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Gets the Converted date. |
66
|
|
|
* |
67
|
|
|
* @return DateRepresentationInterface|null |
68
|
|
|
*/ |
69
|
|
|
public function getTo() |
70
|
|
|
{ |
71
|
|
|
return $this->to; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Sets the Converted date. |
76
|
|
|
* |
77
|
|
|
* @param DateRepresentationInterface $to the to |
78
|
|
|
* |
79
|
|
|
* @return self|null |
80
|
|
|
*/ |
81
|
|
|
public function setTo(DateRepresentationInterface $to) |
82
|
|
|
{ |
83
|
|
|
$this->to = $to; |
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Gets unix time. |
90
|
|
|
* |
91
|
|
|
* @return integer |
92
|
|
|
*/ |
93
|
|
|
public function getUnixTime() |
94
|
|
|
{ |
95
|
|
|
return $this->unixTime; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Sets unix time. |
100
|
|
|
* |
101
|
|
|
* @param integer $unixTime the unix time |
102
|
|
|
* |
103
|
|
|
* @return self |
104
|
|
|
*/ |
105
|
|
|
public function setUnixTime($unixTime) |
106
|
|
|
{ |
107
|
|
|
$this->unixTime = $unixTime; |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Gets unix micro time. |
114
|
|
|
* |
115
|
|
|
* @return integer|null |
116
|
|
|
*/ |
117
|
|
|
public function getUnixMicroTime() |
118
|
|
|
{ |
119
|
|
|
return $this->unixMicroTime; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Sets unix micro time. |
124
|
|
|
* |
125
|
|
|
* @param integer $unixMicroTime the unix microtime |
126
|
|
|
* |
127
|
|
|
* @return self |
128
|
|
|
*/ |
129
|
|
|
public function setUnixMicroTime($unixMicroTime) |
130
|
|
|
{ |
131
|
|
|
$this->unixMicroTime = $unixMicroTime; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|