File: DateTime.from.phpt

package info (click to toggle)
php-nette-utils 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,460 kB
  • sloc: php: 4,146; xml: 9; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 1,176 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
<?php

/**
 * Test: Nette\Utils\DateTime::from().
 */

declare(strict_types=1);

use Nette\Utils\DateTime;
use Tester\Assert;

require __DIR__ . '/../bootstrap.php';


date_default_timezone_set('Europe/Prague');

Assert::same('1978-01-23 11:40:00', (string) DateTime::from(254_400_000));
Assert::same('1978-01-23 11:40:00', (string) (new DateTime)->setTimestamp(254_400_000));
Assert::same(254_400_000, DateTime::from(254_400_000)->getTimestamp());

Assert::same(time() + 60, (int) DateTime::from(60)->format('U'));
Assert::same('2050-08-13 12:40:00', (string) DateTime::from(2_544_000_000));
Assert::same('2050-08-13 12:40:00', (string) (new DateTime)->setTimestamp(2_544_000_000));
Assert::same(is_int(2_544_000_000) ? 2_544_000_000 : '2544000000', DateTime::from(2_544_000_000)->getTimestamp()); // 64 bit

Assert::same('1978-05-05 00:00:00', (string) DateTime::from('1978-05-05'));

Assert::same((new DateTime)->format('Y-m-d H:i:s'), (string) DateTime::from(null));

Assert::type(DateTime::class, DateTime::from(new DateTime('1978-05-05')));

Assert::same('1978-05-05 12:00:00.123450', DateTime::from(new DateTime('1978-05-05 12:00:00.12345'))->format('Y-m-d H:i:s.u'));