Completed
Push — master ( 70b2c3...e706ac )
by Peter
04:34
created

Util   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

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
     *
19
     * @param \DateTime $date
20
     *
21
     * @return \DateTime
22
     */
23 35
    public static function getMondayThisWeek(\DateTime $date)
24
    {
25 35
        $monday = clone $date;
26
27 35
        if ($monday->format('N') != 1) {
28 18
            $monday->modify('Monday this week');
29
30 18
            if ($date->format('Y W') != $monday->format('Y W')) {
31 1
                $monday->modify('-7 day');
32 1
            }
33 18
        }
34
35 35
        return $monday;
36
    }
37
38
    /**
39
     * @param \DateTime $date
40
     * @param int $seconds
41
     *
42
     * @return \DateTime
43
     */
44 10
    public static function roundDate(\DateTime $date, $seconds)
45
    {
46 10
        $date = clone $date;
47
48 10
        return $date->setTimestamp(round($date->getTimestamp() / $seconds) * $seconds);
49
    }
50
}
51