forked from slot/factual-php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffsQuery.php
More file actions
87 lines (77 loc) · 1.88 KB
/
Copy pathDiffsQuery.php
File metadata and controls
87 lines (77 loc) · 1.88 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Represents a Factual Diffs query.
*
* @author Tyler
*
*/
class DiffsQuery {
protected $diffStart = null; // start time. Unix timestamp in milliseconds
protected $diffEnd = null; // Optional end time. Unix timestamp in milliseconds
const RESPONSETYPE = "DiffsResponse";
/**
* Gets Diffs start time in milliseconds
* @return int diffs start time
*/
public function getStart(){
return $this->diffStart;
}
/**
* Gets Diffs end time in milliseconds
* @return int diffs end time
*/
public function getEnd(){
return $this->diffEnd;
}
/**
* The before time to create this diff against.
* @param timestamp Unix timestamp in milliseconds
* @return object This DiffsQuery
*/
public function setStart($timestamp) {
if (!is_numeric($timestamp)){
throw new Exception("Parameter must be millisecond timestamp");
}
$this->diffStart = $timestamp;
return $this;
}
/**
* The after time to create this diff against.
* @param timestamp Unix timestamp in milliseconds
* @return object This DiffsQuery
*/
public function setEnd($timestamp) {
if (!is_numeric($timestamp)){
throw new Exception("Parameter must be millisecond timestamp");
}
$this->diffEnd = $timestamp;
return $this;
}
public function toUrlQuery() {
//assign implied end time
if (empty($this->diffEnd)){
$this->diffEnd = $this->getTimestamp();
}
return "start-date=".$this->diffStart."&end-date=".$this->diffEnd;
}
/**
* Validate Parameters
* @return Bool
*/
public function isValid(){
//use implied end time to validate, but do not set the time itself
if (empty($this->diffEnd)){
$end = $this->getTimestamp();
} else {
$end = $this->diffEnd;
}
if ( empty($this->diffStart)| $this->diffStart >= $end ){
return false;
}
return true;
}
protected function getTimestamp(){
return floor(microtime(true)*1000);
}
}
?>