Completed
Push — master ( 4c5280...5cdc1d )
by Alec
08:43
created

base_timestamp()   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 2
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
/**
11
 * Create a new Carbon instance for the current time.
12
 *
13
 * @param  \DateTimeZone|string|null $tz
14
 * @return \Carbon\Carbon
15
 * @throws \Exception
16
 */
17
function now($tz = null)
18
{
19 1
    return \Carbon\Carbon::now($tz);
20
}
21
22
/**
23
 * @param string|null|int $time
24
 * @param \DateTimeZone|string|null $tz
25
 * @return \Carbon\Carbon
26
 * @throws \Exception
27
 */
28
function carbon($time = null, $tz = null)
29
{
30
    return
31 7
        \is_int($time) ?
32 2
            \Carbon\Carbon::createFromTimestamp($time, $tz) :
33 7
            new \Carbon\Carbon($time, $tz);
34
}
35
36
/**
37
 * Calculate timestamp of start of interval.
38
 *
39
 * @param int $timestamp
40
 * @param int $interval
41
 * @return int
42
 */
43
function base_timestamp(int $timestamp, int $interval = 60): int
44
{
45 36
    return \intdiv($timestamp, $interval) * $interval;
46
}
47