|
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 CreateFromTimestampTest extends AbstractTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function testCreateReturnsDatingInstance() |
|
20
|
|
|
{ |
|
21
|
|
|
$d = Date::createFromTimestamp(Date::create(1975, 5, 21, 22, 32, 5)->getTimestamp()); |
|
22
|
|
|
$this->assertDate($d, 1975, 5, 21, 22, 32, 5); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testCreateFromTimestampUsesDefaultTimezone() |
|
26
|
|
|
{ |
|
27
|
|
|
$d = Date::createFromTimestamp(0); |
|
28
|
|
|
|
|
29
|
|
|
// We know Toronto is -5 since no DST in Jan |
|
30
|
|
|
$this->assertSame(1969, $d->getYear()); |
|
31
|
|
|
$this->assertSame(-5 * 3600, $d->getOffset()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testCreateFromTimestampWithDateTimeZone() |
|
35
|
|
|
{ |
|
36
|
|
|
$d = Date::createFromTimestamp(0, new \DateTimeZone('UTC')); |
|
37
|
|
|
$this->assertSame('UTC', $d->getTimezoneName()); |
|
38
|
|
|
$this->assertDate($d, 1970, 1, 1, 0, 0, 0); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testCreateFromTimestampWithString() |
|
42
|
|
|
{ |
|
43
|
|
|
$d = Date::createFromTimestamp(0, 'UTC'); |
|
44
|
|
|
$this->assertDate($d, 1970, 1, 1, 0, 0, 0); |
|
45
|
|
|
$this->assertSame(0, $d->getOffset()); |
|
46
|
|
|
$this->assertSame('UTC', $d->getTimezoneName()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testCreateFromTimestampGMTDoesNotUseDefaultTimezone() |
|
50
|
|
|
{ |
|
51
|
|
|
$d = Date::createFromTimestampUTC(0); |
|
52
|
|
|
$this->assertDate($d, 1970, 1, 1, 0, 0, 0); |
|
53
|
|
|
$this->assertSame(0, $d->getOffset()); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|