bzr branch
http://darksoft.org/webbzr/adei/trunk
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
1 |
<?php
|
2 |
||
3 |
interface READERTimeInterface { |
|
4 |
public function __construct(READER $reader = NULL, $opts = false); |
|
5 |
public function ImportTime(DateTime $dt); |
|
6 |
public function ExportTime($db_time); |
|
7 |
public function GetTimeSlicingFunction($db_time_var, $width, $offset = 0); |
|
8 |
}
|
|
9 |
||
10 |
||
11 |
abstract class NULLReaderTime implements READERTimeInterface { |
|
12 |
var $gmt_timezone; |
|
13 |
||
14 |
public function __construct(READER $reader = NULL, $opts = false) { |
|
15 |
if ($reader) $this->gmt_timezone = $reader->gmt_timezone; |
|
16 |
else $this->gmt_timezone = new DateTimeZone("GMT"); |
|
17 |
}
|
|
18 |
||
19 |
public function ImportTime(DateTime $dt) { |
|
20 |
throw new ADEIException(translate("CLASS %s: Methods (%s) is not implemented", get_class($this), __METHOD__)); |
|
21 |
}
|
|
22 |
||
23 |
public function ExportTime($db_time) { |
|
24 |
throw new ADEIException(translate("CLASS %s: Methods (%s) is not implemented", get_class($this), __METHOD__)); |
|
25 |
}
|
|
26 |
||
27 |
public function GetTimeSlicingFunction($db_time_var, $width, $offset = 0) { |
|
28 |
throw new ADEIException(translate("CLASS %s: Methods (%s) is not implemented", get_class($this), __METHOD__)); |
|
29 |
}
|
|
30 |
||
31 |
function ImportUnixTime($unix_time) { |
|
146
by Suren A. Chilingaryan
Fixes handling of groups with limited measurement interval, eleminates (int) usag |
32 |
$itime = floor($unix_time); |
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
33 |
|
34 |
if ($itime==$unix_time) { |
|
35 |
// Time zone should be specified, esle "e" output is invalid
|
|
150
by Suren A. Chilingaryan
Escaping of database queries is fixed |
36 |
return $this->ImportTime(new DateTime("@" . sprintf("%f", $itime), $this->gmt_timezone)); |
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
37 |
} else { |
38 |
if (is_float($unix_time)) $subsec = strchr(sprintf("%F", $unix_time), '.'); |
|
39 |
else $subsec = strchr($unix_time, '.'); |
|
40 |
||
41 |
// DS: Due to the bug in PHP (precision is limited to 10ns)
|
|
42 |
if (strlen($subsec) > 9) $subsec = substr($subsec, 0, 9); |
|
43 |
return $this->ImportTime(new DateTime(strftime("%Y-%m-%dT%H:%M:%S", $itime) . $subsec, $this->gmt_timezone)); |
|
44 |
// return $this->ImportTime(new DateTime(strftime("%Y/%m/%d %H:%M:%S", $itime) . $subsec, $this->gmt_timezone));
|
|
45 |
}
|
|
46 |
}
|
|
47 |
||
48 |
function ExportUnixTime($db_time) { |
|
49 |
$dt = $this->ExportTime($db_time); |
|
50 |
return $dt->format("U.u"); |
|
51 |
}
|
|
52 |
}
|
|
53 |
||
54 |
class READERTime extends NULLReaderTime implements READERTimeInterface { |
|
55 |
var $time_zone; |
|
56 |
var $time_format; |
|
57 |
||
58 |
public function __construct(READER $reader = NULL, $opts = false) { |
|
57
by Suren A. Chilingaryan
Fixes in time modules support |
59 |
parent::__construct($reader, $opts); |
60 |
||
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
61 |
$this->time_format = $opts['format']; |
62 |
$this->time_zone = $opts['timezone']; |
|
63 |
}
|
|
64 |
||
65 |
public function ImportTime(DateTime $dt) { |
|
66 |
$dt->setTimezone($this->time_zone); |
|
67 |
return $dt->format($this->time_format); |
|
68 |
}
|
|
69 |
||
70 |
public function ExportTime($db_time) { |
|
71 |
if ($this->time_zone) { |
|
72 |
$ctz = date_default_timezone_get(); |
|
73 |
date_default_timezone_set($this->time_zone->getName()); |
|
160
by Suren A. Chilingaryan
Support for unix timestamps in DBReader |
74 |
switch ($this->time_format) { |
75 |
case "U": |
|
76 |
$dt = new DateTime("@" . $db_time); |
|
77 |
break; |
|
78 |
default: |
|
79 |
$dt = new DateTime($db_time); |
|
80 |
}
|
|
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
81 |
date_default_timezone_set($ctz); |
82 |
||
83 |
// $dt->setTimezone($this->gmt_timezone);
|
|
84 |
return $dt; |
|
85 |
}
|
|
160
by Suren A. Chilingaryan
Support for unix timestamps in DBReader |
86 |
|
87 |
switch ($this->time_format) { |
|
88 |
case "U": |
|
89 |
return new DateTime("@" . $db_time); |
|
90 |
default: |
|
91 |
return new DateTime($db_time); |
|
92 |
}
|
|
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
93 |
}
|
94 |
||
95 |
function GetTimeSlicingFunction($db_time_var, $width, $offset = 0) { |
|
96 |
if ($offset) { |
|
97 |
if (is_object($offset)) |
|
98 |
$off = $this->ImportTime($offset); |
|
99 |
else
|
|
100 |
$off = $this->ImportUnixTime($offset); |
|
101 |
||
102 |
return "($db_time_var - $off) / $width"; |
|
103 |
}
|
|
104 |
||
105 |
return "$db_time_var / $width"; |
|
106 |
}
|
|
107 |
}
|
|
108 |
||
57
by Suren A. Chilingaryan
Fixes in time modules support |
109 |
|
110 |
||
40
by Suren A. Chilingaryan
Resampling, RAWPoint limits, READERTime reorganization, few bugfixes |
111 |
?>
|