Passed
Pull Request — master (#6)
by
unknown
09:05
created

now()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * User: alec
4
 * Date: 12.10.18
5
 * Time: 14:18
6
 */
7
8
namespace AlecRabbit;
9
10
use Carbon\Carbon;
11
12
use Carbon\CarbonInterface;
13
use DateTimeZone;
14
use Exception;
15
16
use function intdiv;
17
use function is_int;
18
19
/**
20
 * Create a new Carbon instance for the current time.
21
 *
22
 * @param  DateTimeZone|string|null $tz
23
 * @return CarbonInterface
24
 * @throws Exception
25
 */
26
function now($tz = null)
27
{
28 1
    return Carbon::now($tz);
29
}
30
31
/**
32
 * @param string|null|int $time
33
 * @param DateTimeZone|string|null $tz
34
 * @return CarbonInterface
35
 * @throws Exception
36
 */
37
function carbon($time = null, $tz = null)
38
{
39
    return
40 13
        is_int($time) ?
41 4
            Carbon::createFromTimestamp($time, $tz) :
42 13
            new Carbon($time, $tz);
43
}
44
45
/**
46
 * Calculate timestamp of start of interval.
47
 *
48
 * @param int $timestamp
49
 * @param int $interval
50
 * @return int
51
 */
52
function base_timestamp(int $timestamp, int $interval = 60): int
53
{
54 36
    return intdiv($timestamp, $interval) * $interval;
55
}
56