-
Notifications
You must be signed in to change notification settings - Fork 0
/
Anlprz_Date.php
78 lines (64 loc) · 1.93 KB
/
Anlprz_Date.php
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
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace anlprz;
Class Anlprz_Date
{
private $startTimestampMillis;
private $endTimestampMillis;
private $dateTime;
private $googleDateTime;
public function __construct( \DateTime $dateObj )
{
try {
$this->dateTime = $dateObj;
$this->reset();
$dateObj->setTime( 0, 0, 0 );
$dateObj->setTimezone( new \DateTimeZone('UTC') );
$this->googleDateTime = $dateObj;
$dateTimeEnd = clone $dateObj;
// adjust from the next day to get end of this day
$dateTimeEnd->modify('+1 day');
$dateTimeEnd->modify('1 second ago');
$start = strtotime( $dateObj->format('Y-m-d H:i:s e') ) * 1000;
if( $start > 1000000000000 )
{
$this->setStartTimeStampMillis( $start );
}
$end = strtotime( $dateTimeEnd->format('Y-m-d H:i:sP') ) * 1000;
if( $end > 1000000000000 )
{
$this->setEndTimeStampMillis( $end );
}
} catch ( \Exception $e ) {
throw new \Exception( $e->getMessage() );
}
}
public function getStartTimeStampMillis()
{
return $this->startTimestampMillis;
}
protected function setStartTimeStampMillis( Int $startTimestampMillis )
{
$this->startTimestampMillis = $startTimestampMillis;
}
public function getEndTimeStampMillis()
{
return $this->endTimestampMillis;
}
protected function setEndTimeStampMillis( Int $endTimestampMillis )
{
$this->endTimestampMillis = $endTimestampMillis;
}
public function getDateTime()
{
return $this->dateTime;
}
public function getGoogleDateTime()
{
return $this->googleDateTime;
}
public function reset()
{
$this->setStartTimeStampMillis( 0 );
$this->setEndTimeStampMillis( 0 );
}
}