• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

h4kuna / data-type / 9206014930

23 May 2024 09:59AM UTC coverage: 97.017% (+0.02%) from 96.994%
9206014930

push

github

h4kuna
feat(Math): method interval support DatetimeInterface

9 of 10 new or added lines in 2 files covered. (90.0%)

1 existing line in 1 file now uncovered.

618 of 637 relevant lines covered (97.02%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/src/Date/Time.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\DataType\Date;
4

5
use DateTime;
6
use DateTimeImmutable;
7
use DateTimeInterface;
8
use h4kuna\DataType\Basic\Strings;
9
use Nette\StaticClass;
10

11
final class Time
12
{
13
        use StaticClass;
14

15
        public static function micro(): float
16
        {
UNCOV
17
                return microtime(true);
×
18
        }
19

20

21
        /**
22
         * string format HH:MM[:SS]
23
         */
24
        public static function only(string|DateTimeInterface $dateTime): int
1✔
25
        {
26
                if (is_string($dateTime)) {
1✔
27
                        $time = Strings::split($dateTime, ':');
1✔
28
                        $hour = $time[0] ?? 0;
1✔
29
                        $minute = $time[1] ?? 0;
1✔
30
                        $second = $time[2] ?? 0;
1✔
31
                } else {
32
                        $hour = $dateTime->format('G');
1✔
33
                        $minute = $dateTime->format('i');
1✔
34
                        $second = $dateTime->format('s');
1✔
35
                }
36

37
                return ((int) $hour) * 3600
1✔
38
                        + ((int) $minute) * 60
1✔
39
                        + ((int) $second);
1✔
40
        }
41

42

43
        /**
44
         * @return ($dateTime is DateTime ? DateTime : DateTimeImmutable)
45
         */
46
        public static function time(
1✔
47
                DateTime|DateTimeImmutable $dateTime,
48
                ?int $hour = null,
49
                ?int $minutes = null,
50
                ?int $seconds = null,
51
                ?int $microseconds = null,
52
        ): DateTime|DateTimeImmutable
53
        {
54
                return $dateTime->setTime(
1✔
55
                        $hour ?? (int) $dateTime->format('G'),
1✔
56
                        $minutes ?? (int) $dateTime->format('i'),
1✔
57
                        $seconds ?? (int) $dateTime->format('s'),
1✔
58
                        $microseconds ?? (int) $dateTime->format('u'),
1✔
59
                );
60
        }
61

62

63
        /**
64
         * @return ($dateTime is DateTime ? DateTime : DateTimeImmutable)
65
         */
66
        public static function date(
1✔
67
                DateTime|DateTimeImmutable $dateTime,
68
                ?int $year = null,
69
                ?int $month = null,
70
                ?int $day = null,
71
        ): DateTime|DateTimeImmutable
72
        {
73
                return $dateTime->setDate(
1✔
74
                        $year ?? (int) $dateTime->format('Y'),
1✔
75
                        $month ?? (int) $dateTime->format('n'),
1✔
76
                        $day ?? (int) $dateTime->format('j'),
1✔
77
                );
78
        }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc