-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathDateTime.createFromFormat.phpt
More file actions
29 lines (18 loc) · 1.03 KB
/
DateTime.createFromFormat.phpt
File metadata and controls
29 lines (18 loc) · 1.03 KB
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
<?php
/**
* Test: Nette\Utils\DateTime::createFromFormat().
*/
declare(strict_types=1);
use Tester\Assert;
use Nette\Utils\DateTime;
require __DIR__ . '/../bootstrap.php';
date_default_timezone_set('Europe/Prague');
Assert::type(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', '2050-08-13 11:40:00'));
Assert::type(DateTime::class, DateTime::createFromFormat('Y-m-d H:i:s', '2050-08-13 11:40:00', new DateTimeZone('Europe/Prague')));
Assert::same('2050-08-13 11:40:00.123450', DateTime::createFromFormat('Y-m-d H:i:s.u', '2050-08-13 11:40:00.12345')->format('Y-m-d H:i:s.u'));
Assert::same('Europe/Prague', DateTime::createFromFormat('Y', '2050')->getTimezone()->getName());
Assert::same('Europe/Bratislava', DateTime::createFromFormat('Y', '2050', 'Europe/Bratislava')->getTimezone()->getName());
Assert::error(function () {
DateTime::createFromFormat('Y-m-d H:i:s', '2050-08-13 11:40:00', 5);
}, Nette\InvalidArgumentException::class, 'Invalid timezone given');
Assert::null(DateTime::createFromFormat('Y-m-d', '2014-10'));