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

Cecilapp / Cecil / 21900210283

11 Feb 2026 09:48AM UTC coverage: 77.124%. First build
21900210283

Pull #2313

github

web-flow
Merge 8a1111676 into ef8bfe522
Pull Request #2313: Parallelize page conversion using pcntl

79 of 129 new or added lines in 4 files covered. (61.24%)

3196 of 4144 relevant lines covered (77.12%)

0.77 hits per line

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

81.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
        // wrong type
57
        if (!\is_string($date)) {
1✔
NEW
58
            throw new \Exception(\sprintf('$date (%s) must be a string, an integer timestamp, or an instance of DateTime/DateTimeImmutable.', get_debug_type($date)));
×
59
        }
60

61
        return new \DateTime($date);
1✔
62
    }
63

64
    /**
65
     * Duration in seconds to ISO 8601.
66
     */
67
    public static function durationToIso8601(float $duration): string
68
    {
69
        $duration = (int) round($duration);
1✔
70
        $dateInterval = \DateInterval::createFromDateString("$duration seconds");
1✔
71

72
        return $dateInterval->format('PT%HH%IM%SS');
1✔
73
    }
74
}
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