Completed
Push — master ( 7f4fe5...70b2c3 )
by Peter
02:55
created

Util   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 40
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMondayThisWeek() 0 14 3
A roundDate() 0 6 1
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Bundle\DateBundle;
11
12
class Util
13
{
14
    /**
15
     * Bugfix for get monday of this week.
16
     *
17
     * @see https://bugs.php.net/bug.php?id=63740
18
     * @codeCoverageIgnore
19
     *
20
     * @param \DateTime $date
21
     *
22
     * @return \DateTime
23
     */
24
    public static function getMondayThisWeek(\DateTime $date)
25
    {
26
        $monday = clone $date;
27
28
        if ($monday->format('N') != 1) {
29
            $monday->modify('Monday this week');
30
31
            if ($date->format('Y W') != $monday->format('Y W')) {
32
                $monday->modify('-7 day');
33
            }
34
        }
35
36
        return $monday;
37
    }
38
39
    /**
40
     * @param \DateTime $date
41
     * @param int $seconds
42
     *
43
     * @return \DateTime
44
     */
45 8
    public static function roundDate(\DateTime $date, $seconds)
46
    {
47 8
        $date = clone $date;
48
49 8
        return $date->setTimestamp(round($date->getTimestamp() / $seconds) * $seconds);
50
    }
51
}
52