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

contributte / datagrid / 8685602316

13 Mar 2024 12:24PM UTC coverage: 34.102%. Remained the same
8685602316

push

github

web-flow
[7.x] Next (#1060)

* PHP 8.0

* Translator: switch from ITranslator to Translator (#973)

* [7.x] Bootstrap 5 + PHP 8 + vanilla javascript (#1021)

* Bootstrap 5

* Bootstrap 5 (docs)

* Bootstrap 5

* form-control -> form-select

* Bump bootstrap-select for Bootstrap 5 support

* Removed `input-sm` from Bootstrap 3

See https://getbootstrap.com/docs/4.0/migration/#forms-1

* Bootstrap 5: When selectpicker, replace form-select classes with form-control and refresh it

* Hide `underline` also for `dropdown-item`. And merged into one CSS rule.

* Update the filterMultiSelect initialization

* Text-align: left -> start

Co-authored-by: Radim Vaculík <radim.vaculik@gmail.com>
Co-authored-by: Jaroslav Líbal <jaroslav.libal@neatous.cz>

* [7.x] phpstan-deprecation-rules (#1061)

* Fix sort

* Add method for setting custom Action href, v6.x (#853)

* [7.x] Nextras ORM 4 support, closes #984

* Fix ElasticsearchDataSource.php data source (#1041)

* Error: Typed property Ublaboo\DataGrid\InlineEdit\InlineEdit::$itemID must not be accessed before initialization

* composer: allow-plugins: php-http/discovery

* ItemDetailForm: $httpPost: Typed property must not be accessed...

* phpstan: revert  --memory-limit=4G

* NetteDatabaseSelectionHelper: Context -> Explorer, getSupplementalDriver -> getDriver

* Update README.md

* Templates: fix variables

* data-bs-toggle attribute for multiaction button (#1072)

* dependabot.yml (#1078)

* Allow nette/utils:4.0 (#1077)

* Add onColumnShow and onColumnHide event methods (#1076)

* Add onColumnShow and onColumnHide event methods

* Add native type array

* Removed duplicity

* Return value of BackedEnum when reading Doctrine entity property. (#1081)

* Return value of BackedEnum when reading array value (#1083)

* Added method to check if filter is on default values; Closes #1082 (#1084)

* ublaboo -> contributte (#1067) (#1075)

* Delete depe... (continued)

117 of 435 new or added lines in 54 files covered. (26.9%)

1455 existing lines in 67 files now uncovered.

1124 of 3296 relevant lines covered (34.1%)

0.34 hits per line

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

0.0
/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
use DateTimeZone;
9

10
final class DateTimeHelper
11
{
12

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

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

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

NEW
53
                if ($value instanceof DateTime) {
×
54
                        return $value;
×
55
                }
56

UNCOV
57
                if ($value instanceof DateTimeImmutable) {
×
58
                        /** @var DateTimeZone|false $tz */
UNCOV
59
                        $tz = $value->getTimezone();
×
NEW
60
                        $date = new DateTime('now', $tz !== false ? $tz : null);
×
61
                        $date->setTimestamp($value->getTimestamp());
×
62

UNCOV
63
                        return $date;
×
64
                }
65

UNCOV
66
                foreach ($formats as $format) {
×
NEW
67
                        $date = DateTime::createFromFormat($format, (string) $value);
×
68

UNCOV
69
                        if ($date === false) {
×
UNCOV
70
                                continue;
×
71
                        }
72

73
                        return $date;
×
74
                }
75

UNCOV
76
                $timestamp = strtotime((string) $value);
×
77

UNCOV
78
                if ($timestamp !== false) {
×
NEW
79
                        $date = new DateTime();
×
80
                        $date->setTimestamp($timestamp);
×
81

UNCOV
82
                        return $date;
×
83
                }
84

NEW
85
                throw new DatagridDateTimeHelperException();
×
86
        }
87

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

© 2025 Coveralls, Inc