DateTimeHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
c 1
b 0
f 0
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A makeDateTimeFromDateString() 0 3 1
A makeFromTimestamp() 0 3 1
A makeTimestampFromDateString() 0 3 1
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Core\Helpers;
4
5
class DateTimeHelper
6
{
7
    /**
8
     * Создание объекта DateTime на основе полученного timestamp
9
     *
10
     * @param int $timestamp
11
     * @return \DateTime
12
     */
13
    public static function makeFromTimestamp(int $timestamp): \DateTime
14
    {
15
        return (new \DateTime())->setTimestamp(intdiv($timestamp, 1000));
16
    }
17
18
    /**
19
     * Преобразование строки даты/времени в объект DateTime
20
     *
21
     * @param string $datetime
22
     * @return \DateTime
23
     * @throws \DateMalformedStringException
24
     */
25
    public static function makeDateTimeFromDateString(string $datetime): \DateTime
26
    {
27
        return new \DateTime($datetime);
28
    }
29
30
    /**
31
     * Создание timestamp на основе строки даты/времени
32
     *
33
     * @param string $datetime
34
     * @return int
35
     * @throws \DateMalformedStringException
36
     */
37
    public static function makeTimestampFromDateString(string $datetime): int
38
    {
39
        return (new \DateTime($datetime))->getTimestamp() * 1000;
40
    }
41
}
42