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

daycry / jobs / 19498141349

19 Nov 2025 10:30AM UTC coverage: 62.5% (+0.7%) from 61.815%
19498141349

push

github

daycry
- Fixes

4 of 4 new or added lines in 4 files covered. (100.0%)

41 existing lines in 9 files now uncovered.

1145 of 1832 relevant lines covered (62.5%)

4.69 hits per line

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

71.43
/src/Libraries/DateTimeHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Queues.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Jobs\Libraries;
15

16
use DateTimeImmutable;
17
use DateTimeInterface;
18
use Throwable;
19

20
final class DateTimeHelper
21
{
22
    /**
23
     * Parse a mixed date/time input into a \DateTimeImmutable or null.
24
     * Accepts: DateTimeInterface (cloned), numeric timestamp, string parseable by DateTime,
25
     * or null. Returns null on failure.
26
     */
27
    public static function parseImmutable(mixed $value): ?DateTimeImmutable
28
    {
29
        if ($value instanceof DateTimeImmutable) {
11✔
UNCOV
30
            return $value;
×
31
        }
32
        if ($value instanceof DateTimeInterface) {
11✔
33
            return DateTimeImmutable::createFromInterface($value);
×
34
        }
35
        if (is_numeric($value)) {
11✔
36
            try {
37
                return (new DateTimeImmutable())->setTimestamp((int) $value);
1✔
38
            } catch (Throwable) {
×
39
                return null;
×
40
            }
41
        }
42
        if (is_string($value) && $value !== '') {
10✔
43
            try {
44
                return new DateTimeImmutable($value);
3✔
45
            } catch (Throwable) {
1✔
46
                return null;
1✔
47
            }
48
        }
49

50
        return null;
9✔
51
    }
52

53
    /**
54
     * Convenience: now() wrapper for consistency and easier test stubbing later.
55
     */
56
    public static function now(): DateTimeImmutable
57
    {
58
        return new DateTimeImmutable('now');
8✔
59
    }
60
}
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