Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace ZipStream;
6
 
7
use DateInterval;
8
use DateTimeImmutable;
9
use DateTimeInterface;
10
use ZipStream\Exception\DosTimeOverflowException;
11
 
12
/**
13
 * @internal
14
 */
15
abstract class Time
16
{
17
    private const DOS_MINIMUM_DATE = '1980-01-01 00:00:00Z';
18
 
19
    public static function dateTimeToDosTime(DateTimeInterface $dateTime): int
20
    {
21
        $dosMinimumDate = new DateTimeImmutable(self::DOS_MINIMUM_DATE);
22
 
23
        if ($dateTime->getTimestamp() < $dosMinimumDate->getTimestamp()) {
24
            throw new DosTimeOverflowException(dateTime: $dateTime);
25
        }
26
 
27
        $dateTime = DateTimeImmutable::createFromInterface($dateTime)->sub(new DateInterval('P1980Y'));
28
 
29
        ['year' => $year,
30
            'mon' => $month,
31
            'mday' => $day,
32
            'hours' => $hour,
33
            'minutes' => $minute,
34
            'seconds' => $second
35
        ] = getdate($dateTime->getTimestamp());
36
 
37
        return
38
            ($year << 25) |
39
            ($month << 21) |
40
            ($day << 16) |
41
            ($hour << 11) |
42
            ($minute << 5) |
43
            ($second >> 1);
44
    }
45
}