forked from shinobushiva/Water
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
93 lines (78 loc) · 2.46 KB
/
index.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
date_default_timezone_set('asia/tokyo');
require_once('dbconnect.php');
$connect = open_db();
mysqli_query($connect, 'SET NAMES utf8');
mysqli_set_charset($connect, 'utf8');
mysqli_select_db($connect, '');
$now = time();
$from_time = $now - (60 * 60 * 24 * 2);
error_log($from_time);
$query = 'select * from info where time> ' . $from_time . ' order by time asc';
error_log($query);
$res = mysqli_query($connect, $query);
function json_safe_encode($data){
return json_encode($data, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT);
}
/**
*
* 日時の切り上げ/切捨て/四捨五入
*
* @param string $date
* @param integer $place 1|10|100|1000|10000|100000
* @param string $math ceil|floor|round
* @return string
*/
function getDateRound($date, $place, $math)
{
list($Y, $m, $d, $H, $i, $s) = explode("-", date('Y-m-d-H-i-s', strtotime($date)));
// 秒(1で1の位、10で秒全体)
if ($place == 1) {
$s = $math($s * 0.1) * 10;
} elseif ($place > 1) {
$s = $math($s * 0.01) * 100;
if ($s > 60) {
$s = 60;
}
}
if ($place > 10) {
$date = date('Y-m-d-H-i-s', mktime($H, $i, $s, $m, $d, $Y));
list($Y, $m, $d, $H, $i, $s) = explode("-", $date);
}
// 分(100で1の位、1000で分全体)
if ($place == 100) {
$i = $math($i * 0.1) * 10;
} elseif ($place > 100) {
$i = $math($i * 0.01) * 100;
if ($i > 60) {
$i = 60;
}
}
if ($place > 1000) {
$date = date('Y-m-d-H-i-s', mktime($H, $i, $s, $m, $d, $Y));
list($Y, $m, $d, $H, $i, $s) = explode("-", $date);
}
// 時間(10000で1の位、100000で時間全体)
if ($place == 10000) {
$H = $math($H * 0.1) * 10;
} elseif ($place > 10000) {
$H = $math($H * 0.01) * 100;
if ($H > 24) {
$H = 24;
}
}
return date('Y-m-d H:i:s', mktime($H, $i, $s, $m, $d, $Y));
}
$arr = array();
while ($data = mysqli_fetch_array($res)) {
// $json = $json . json_encode($data);
// //$json = $json. '{locate:"'. $data['locate']. '",time:'. $data['time'] .',flg:'. $data['flg']. '},';
// $json = $json . ',';
$arr[] = $data;
}
$from_time = strtotime(getDateRound(date("Y-m-d H:i:s", $arr[0]['time']), 100, "floor"));
$now = strtotime(getDateRound(date("Y-m-d H:i:s", $now), 100, "ceil"));
$json = json_safe_encode($arr);
//error_log($json);
mysqli_close($connect);
include 'views/index.php';