File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ <?
2+
3+ namespace TgUtils ;
4+
5+ class DateRange {
6+
7+ protected $ from ;
8+ protected $ until ;
9+
10+ public function __construct ($ from = NULL , $ until = NULL ) {
11+ $ this ->from = $ from ;
12+ $ this ->until = $ until ;
13+ }
14+
15+ public function setFrom ($ value ) {
16+ $ this ->from = $ value ;
17+ $ this ->checkRange ();
18+ return $ this ;
19+ }
20+
21+ public function getFrom () {
22+ return $ this ->from ;
23+ }
24+
25+ public function setUntil ($ value ) {
26+ $ this ->until = $ value ;
27+ $ this ->checkRange ();
28+ return $ this ;
29+ }
30+
31+ public function getUntil () {
32+ return $ this ->until ;
33+ }
34+
35+ public function set ($ from , $ until ) {
36+ $ this ->from = $ from ;
37+ $ this ->until = $ until ;
38+ $ this ->checkRange ();
39+ return $ this ;
40+ }
41+
42+ protected function checkRange () {
43+ if (($ this ->from != NULL ) && ($ this ->until != NULL )) {
44+ if ($ this ->from ->toUnix () > $ this ->until ->toUnix ()) {
45+ $ foo = $ this ->until ;
46+ $ this ->until = $ this ->from ;
47+ $ this ->from = $ foo ;
48+ }
49+ }
50+ }
51+
52+ public function __toString () {
53+ $ rc = ($ this ->from != NULL ) ? $ this ->from ->toMySql (TRUE ) : 'N/A ' ;
54+ $ rc .= ' - ' ;
55+ $ rc .= ($ this ->until != NULL ) ? $ this ->until ->toMySql (TRUE ) : 'N/A ' ;
56+ return $ rc ;
57+ }
58+ }
59+
You can’t perform that action at this time.
0 commit comments