Time::secondsToDifference()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 8
nop 1
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 . ':' : '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
75
        $ret .= sprintf('%02d', $m) . ':' . sprintf('%02d', $s);
76
        return $ret;
77
    }
78
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
79