1
|
|
|
<?php |
2
|
|
|
class Time |
3
|
|
|
{ |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Returns true if given date is today. |
7
|
|
|
* |
8
|
|
|
* @param string $date Unix timestamp |
9
|
|
|
* @return boolean True if date is today |
10
|
|
|
*/ |
11
|
|
|
public static function isToday($date) |
12
|
|
|
{ |
13
|
|
|
return date('Y-m-d', $date) == date('Y-m-d', time()); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Returns true if given date was yesterday |
18
|
|
|
* |
19
|
|
|
* @param string $date Unix timestamp |
20
|
|
|
* @return boolean True if date was yesterday |
21
|
|
|
*/ |
22
|
|
|
public static function wasYesterday($date) |
23
|
|
|
{ |
24
|
|
|
return date('Y-m-d', $date) == date('Y-m-d', strtotime('yesterday')); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Returns true if given date is in this year |
29
|
|
|
* |
30
|
|
|
* @param string $date Unix timestamp |
31
|
|
|
* @return boolean True if date is in this year |
32
|
|
|
*/ |
33
|
|
|
public static function isThisYear($date) |
34
|
|
|
{ |
35
|
|
|
return date('Y', $date) == date('Y', time()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Returns true if given date is in this week |
40
|
|
|
* |
41
|
|
|
* @param string $date Unix timestamp |
42
|
|
|
* @return boolean True if date is in this week |
43
|
|
|
*/ |
44
|
|
|
public static function isThisWeek($date) |
45
|
|
|
{ |
46
|
|
|
return date('W Y', $date) == date('W Y', time()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns true if given date is in this month |
51
|
|
|
* |
52
|
|
|
* @param string $date Unix timestamp |
53
|
|
|
* @return boolean True if date is in this month |
54
|
|
|
*/ |
55
|
|
|
public static function isThisMonth($date) |
56
|
|
|
{ |
57
|
|
|
return date('m Y', $date) == date('m Y', time()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public static function secondsToDifference($seconds) |
61
|
|
|
{ |
62
|
|
|
$diff = $seconds; |
63
|
|
|
if ($h=intval((floor($diff/3600)))) { |
64
|
|
|
$diff = $diff % 3600; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
if ($m=intval((floor($diff/60)))) { |
68
|
|
|
$diff = $diff % 60; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$s = intval($diff); |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
$ret = $h ? $h . ':' : ''; |
|
|
|
|
75
|
|
|
$ret .= sprintf('%02d', $m) . ':' . sprintf('%02d', $s); |
76
|
|
|
return $ret; |
77
|
|
|
} |
78
|
|
|
} |
|
|
|
|
79
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.