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

contributte / datagrid / 22278243943

22 Feb 2026 01:39PM UTC coverage: 50.577% (+1.9%) from 48.715%
22278243943

Pull #1253

github

web-flow
Merge a33d2af89 into f39da7e53
Pull Request #1253: Add NetteDatabaseDataSource for raw SQL queries via Nette\Database\Explorer

128 of 128 new or added lines in 1 file covered. (100.0%)

66 existing lines in 4 files now uncovered.

1491 of 2948 relevant lines covered (50.58%)

0.51 hits per line

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

65.22
/src/Utils/DateTimeHelper.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\Utils;
4

5
use Contributte\Datagrid\Exception\DatagridDateTimeHelperException;
6
use DateTime;
7
use DateTimeImmutable;
8

9
final class DateTimeHelper
10
{
11

12
        /**
13
         * Try to convert string into \DateTime object
14
         *
15
         * @param array|string[] $formats
16
         * @throws DatagridDateTimeHelperException
17
         */
18
        public static function tryConvertToDateTime(mixed $value, array $formats = []): DateTime
1✔
19
        {
20
                return self::fromString($value, $formats);
1✔
21
        }
22

23
        /**
24
         * Try to convert string into \DateTime object from more date formats
25
         *
26
         * @param array|string[] $formats
27
         * @throws DatagridDateTimeHelperException
28
         */
29
        public static function tryConvertToDate(mixed $value, array $formats = []): DateTime
30
        {
UNCOV
31
                return self::fromString($value, $formats);
×
32
        }
33

34
        /**
35
         * Convert string into \DateTime object from more date without time
36
         *
37
         * @param array|string[] $formats
38
         * @throws DatagridDateTimeHelperException
39
         */
40
        public static function fromString(mixed $value, array $formats = []): DateTime
1✔
41
        {
42
                $formats = array_merge($formats, [
1✔
43
                        'Y-m-d H:i:s.u',
1✔
44
                        'Y-m-d H:i:s',
45
                        'Y-m-d',
46
                        'j. n. Y G:i:s',
47
                        'j. n. Y G:i',
48
                        'j. n. Y',
49
                        'U',
50
                ]);
51

52
                if ($value instanceof DateTime) {
1✔
UNCOV
53
                        return $value;
×
54
                }
55

56
                if ($value instanceof DateTimeImmutable) {
1✔
UNCOV
57
                        $date = new DateTime('now', $value->getTimezone());
×
UNCOV
58
                        $date->setTimestamp($value->getTimestamp());
×
59

UNCOV
60
                        return $date;
×
61
                }
62

63
                foreach ($formats as $format) {
1✔
64
                        $date = DateTime::createFromFormat($format, (string) $value);
1✔
65

66
                        if ($date === false) {
1✔
67
                                continue;
1✔
68
                        }
69

70
                        return $date;
1✔
71
                }
72

73
                $timestamp = strtotime((string) $value);
1✔
74

75
                if ($timestamp !== false) {
1✔
UNCOV
76
                        $date = new DateTime();
×
UNCOV
77
                        $date->setTimestamp($timestamp);
×
78

UNCOV
79
                        return $date;
×
80
                }
81

82
                throw new DatagridDateTimeHelperException();
1✔
83
        }
84

85
}
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