xref: /PHP-7.4/ext/date/tests/oo_001.phpt (revision a9e5e222)
1--TEST--
2date OO interface
3--FILE--
4<?php
5date_default_timezone_set('UTC');
6class _d extends DateTime {
7	function __construct() {
8	}
9}
10class _t extends DateTimeZone {
11	function __construct() {
12	}
13}
14
15$d = new DateTime;
16var_dump($d->format("Y-m-d H:i:s"));
17
18$d = new _d;
19var_dump($d->format("Y-m-d H:i:s"));
20
21try {
22	new DateTime("1am todax");
23} catch (Exception $e) {
24	echo $e->getMessage(),"\n";
25}
26
27$t = new DateTimeZone("UTC");
28var_dump($t->getName());
29
30$t = new _t;
31var_dump($t->getName());
32
33try {
34	new DateTimeZone("GottaFindThisOne");
35} catch (Exception $e) {
36	echo $e->getMessage(),"\n";
37}
38
39echo "DONE\n";
40?>
41--EXPECTF--
42string(19) "%d-%d-%d %d:%d:%d"
43
44Warning: DateTime::format(): The DateTime object has not been correctly initialized by its constructor in %soo_001.php on line %d
45bool(false)
46DateTime::__construct(): Failed to parse time string (1am todax) at position 4 (t): The timezone could not be found in the database
47string(3) "UTC"
48
49Warning: DateTimeZone::getName(): The DateTimeZone object has not been correctly initialized by its constructor in %soo_001.php on line %d
50bool(false)
51DateTimeZone::__construct(): Unknown or bad timezone (GottaFindThisOne)
52DONE
53