File: DateTest.php

package info (click to toggle)
php-kissifrot-php-ixr 1.8.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 220 kB
  • sloc: php: 1,152; makefile: 25; xml: 21
file content (54 lines) | stat: -rw-r--r-- 1,422 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

namespace IXR\tests\DataType;

use IXR\DataType\Date;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class DateTest extends TestCase
{

    /**
     * @return array
     * @see testParseIso
     */
    static function provideDates()
    {
        return [
            // full datetime, different formats
            ['2010-08-17T09:23:14', 1282036994],
            ['20100817T09:23:14', 1282036994],
            ['2010-08-17 09:23:14', 1282036994],
            ['20100817 09:23:14', 1282036994],
            ['2010-08-17T09:23:14Z', 1282036994],
            ['20100817T09:23:14Z', 1282036994],

            // with timezone
            ['2010-08-17 09:23:14+0000', 1282036994],
            ['2010-08-17 09:23:14+00:00', 1282036994],
            ['2010-08-17 12:23:14+03:00', 1282036994],

            // no seconds
            ['2010-08-17T09:23', 1282036980],
            ['20100817T09:23', 1282036980],

            // no time
            ['2010-08-17', 1282003200],
            [1282036980, 1282036980],
//            ['20100817', 1282003200], #this will NOT be parsed, but is assumed to be timestamp
        ];
    }

    /**
     * @param mixed $input
     * @param int $expect
     */
    #[DataProvider('provideDates')]
    static function testParseIso($input, $expect)
    {
        $dt = new Date($input);
        self::assertEquals($expect, $dt->getTimeStamp());
    }

}