|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HMLB\Date\Tests\Date; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Date package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Hugues Maignol <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
use HMLB\Date\Date; |
|
15
|
|
|
use HMLB\Date\Tests\AbstractTestCase; |
|
16
|
|
|
|
|
17
|
|
|
class CreateFromFormatTest extends AbstractTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testCreateFromFormatReturnsDate() |
|
20
|
|
|
{ |
|
21
|
|
|
$d = Date::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11'); |
|
22
|
|
|
$this->assertDate($d, 1975, 5, 21, 22, 32, 11); |
|
23
|
|
|
$this->assertTrue($d instanceof Date); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testCreateFromFormatWithTimezoneString() |
|
27
|
|
|
{ |
|
28
|
|
|
$d = Date::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', 'Europe/London'); |
|
29
|
|
|
$this->assertDate($d, 1975, 5, 21, 22, 32, 11); |
|
30
|
|
|
$this->assertSame('Europe/London', $d->getTimezoneName()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testCreateFromFormatWithTimezone() |
|
34
|
|
|
{ |
|
35
|
|
|
$d = Date::createFromFormat('Y-m-d H:i:s', '1975-05-21 22:32:11', new \DateTimeZone('Europe/London')); |
|
36
|
|
|
$this->assertDate($d, 1975, 5, 21, 22, 32, 11); |
|
37
|
|
|
$this->assertSame('Europe/London', $d->getTimezoneName()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testCreateFromFormatWithMillis() |
|
41
|
|
|
{ |
|
42
|
|
|
$d = Date::createFromFormat('Y-m-d H:i:s.u', '1975-05-21 22:32:11.254687'); |
|
43
|
|
|
$this->assertSame(254687, $d->getMicro()); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|