-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.php
executable file
·99 lines (88 loc) · 1.96 KB
/
util.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
93
94
95
96
97
98
99
<?php
include_once ('db.class.php');
class Util {
function __construct() {
}
public function nextBoiled() {
// prev_time+interval-now
$db = new DBManager();
$sfhero = $db -> getSfHero();
if ($sfhero == null) {
echo "no object.";
}
$pvs_time = $sfhero -> created_at;
echo $pvs_time . '</br>';
// $pvs_time='2011-12-28 20:49:19';
$now = date('Y-m-d H:i:s');
echo $now . '</br>';
$interval = $db -> getInterval();
$ret = $this -> dateDiff('n', $pvs_time, $now);
$ret = $interval-$ret;
// echo "diff=" . $ret;
return $ret;
}
function hasKeyword($text)
{
if (substr_count($text, '多久') > 0)
return 1;
return 0;
}
// 以下代码来自 最佳TV,春哥超赞 [兔子]
function transformDate($date) {
$sp = explode(" ", $date);
$ret = $sp[5] . "-" . $this -> getMonth($sp[1]) . "-" . $sp[2] . " " . $sp[3];
return $ret;
}
function getMonth($str) {
if ($str == 'Jan')
return 1;
if ($str == 'Feb')
return 2;
if ($str == 'Mar')
return 3;
if ($str == 'Apr')
return 4;
if ($str == 'May')
return 5;
if ($str == 'Jun')
return 6;
if ($str == 'Jul')
return 7;
if ($str == 'Aug')
return 8;
if ($str == 'Sep')
return 9;
if ($str == 'Oct')
return 10;
if ($str == 'Nov')
return 11;
if ($str == 'Dec')
return 12;
return 0;
}
function dateDiff($interval, $date1, $date2) {
$retval = 0;
$d1 = strtotime($date1);
$d2 = strtotime($date2);
$time_difference = $d2 - $d1;
switch ($interval) {
case "w" :
$retval = bcdiv($time_difference, 604800);
break;
case "d" :
$retval = bcdiv($time_difference, 86400);
break;
case "h" :
$retval = bcdiv($time_difference, 3600);
break;
case "n" :
$retval = bcdiv($time_difference, 60);
break;
case "s" :
$retval = $time_difference;
break;
}
return $retval;
}
}
?>