Completed
Pull Request — master (#2)
by
unknown
01:11
created

Time::inMillis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace TraderInteractive\Util;
4
5
use InvalidArgumentException;
6
7
/**
8
 * Static class for time based functions.
9
 */
10
final class Time
11
{
12
    /**
13
     * Converts unix timestamp into an ansi sql timestamp literal
14
     *
15
     * @param int $unixTimestamp
16
     *
17
     * @return string ansi sql timestamp surrounded with parenthesis
18
     *
19
     * @throws InvalidArgumentException if $unixTimestamp was not an int
20
     */
21
    public static function getAnsiSqlTimestamp(int $unixTimestamp) : string
22
    {
23
        return "(TIMESTAMP'" . date('Y-m-d H:i:s', $unixTimestamp) . "')";
24
    }
25
26
    /**
27
     * Get current unix time in milliseconds
28
     *
29
     * @return int the current unix time
30
     */
31
    public static function inMillis() : int
32
    {
33
        return (int)(microtime(true) * 1000);
34
    }
35
}
36