xref: /PHP-8.2/ext/date/tests/oo_001.phpt (revision 2f1d0f2b)
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}
14class _p extends DatePeriod {
15    function __construct() {
16    }
17}
18
19$d = new DateTime;
20var_dump($d->format("Y-m-d H:i:s"));
21
22try {
23    $d = new _d;
24    var_dump($d->format("Y-m-d H:i:s"));
25} catch (Error $e) {
26    echo $e->getMessage(),"\n";
27}
28
29try {
30    new DateTime("1am todax");
31} catch (Exception $e) {
32    echo $e->getMessage(),"\n";
33}
34
35$t = new DateTimeZone("UTC");
36var_dump($t->getName());
37
38try {
39    $t = new _t;
40    var_dump($t->getName());
41} catch (Error $e) {
42    echo $e->getMessage(),"\n";
43}
44
45try {
46    new DateTimeZone("GottaFindThisOne");
47} catch (Exception $e) {
48    echo $e->getMessage(),"\n";
49}
50
51$p = new _p;
52try {
53    var_dump($p->getStartDate());
54} catch (Error $e) {
55    echo $e->getMessage(),"\n";
56}
57try {
58    var_dump($p->getDateInterval());
59} catch (Error $e) {
60    echo $e->getMessage(),"\n";
61}
62
63echo "DONE\n";
64?>
65--EXPECTF--
66string(19) "%d-%d-%d %d:%d:%d"
67The DateTime object has not been correctly initialized by its constructor
68Failed to parse time string (1am todax) at position 4 (t): The timezone could not be found in the database
69string(3) "UTC"
70The DateTimeZone object has not been correctly initialized by its constructor
71DateTimeZone::__construct(): Unknown or bad timezone (GottaFindThisOne)
72The DatePeriod object has not been correctly initialized by its constructor
73The DatePeriod object has not been correctly initialized by its constructor
74DONE
75