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

Cecilapp / Cecil / 17077869193

19 Aug 2025 06:02PM UTC coverage: 77.077% (-0.3%) from 77.377%
17077869193

push

github

ArnaudLigny
feat: new Twig filter `highlight`

1 of 2 new or added lines in 1 file covered. (50.0%)

12 existing lines in 3 files now uncovered.

2969 of 3852 relevant lines covered (77.08%)

0.77 hits per line

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

56.25
/src/Util/Date.php
1
<?php
2

3
/**
4
 * This file is part of Cecil.
5
 *
6
 * (c) Arnaud Ligny <arnaud@ligny.fr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace Cecil\Util;
15

16
/**
17
 * Date utility class.
18
 *
19
 * This class provides utility methods for handling dates,
20
 * including validation, conversion to DateTime, and formatting durations.
21
 */
22
class Date
23
{
24
    /**
25
     * Checks if a date is valid.
26
     */
27
    public static function isValid(string $date, string $format = 'Y-m-d'): bool
28
    {
29
        $d = \DateTime::createFromFormat($format, $date);
1✔
30

31
        return $d && $d->format($format) === $date;
1✔
32
    }
33

34
    /**
35
     * Date to DateTime.
36
     *
37
     * @param mixed $date
38
     */
39
    public static function toDatetime($date): \DateTime
40
    {
41
        if ($date === null) {
1✔
42
            throw new \Exception('$date can\'t be null.');
×
43
        }
44
        // DateTime
45
        if ($date instanceof \DateTime) {
1✔
46
            return $date;
1✔
47
        }
48
        // DateTimeImmutable
49
        if ($date instanceof \DateTimeImmutable) {
1✔
50
            return \DateTime::createFromImmutable($date);
1✔
51
        }
52
        // timestamp
53
        if (\is_int($date)) {
1✔
54
            return (new \DateTime())->setTimestamp($date);
×
55
        }
56

57
        return new \DateTime($date);
1✔
58
    }
59

60
    /**
61
     * Duration in seconds to ISO 8601.
62
     * e.g.: '00:00:46.70' -> 'T0M46S'
63
     */
64
    public static function durationToIso8601(string $duration): string
65
    {
UNCOV
66
        $time = new \DateTime($duration);
×
UNCOV
67
        $midnight = new \DateTime();
×
UNCOV
68
        $midnight->setTime(0, 0);
×
UNCOV
69
        $period = $midnight->diff($time);
×
70

UNCOV
71
        return $period->format('T%iM%SS');
×
72
    }
73
}
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