xref: /PHP-8.4/ext/date/tests/oo_001.phpt (revision b7860cd5)
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::class, ': ', $e->getMessage(), "\n";
27}
28
29try {
30    new DateTime("1am todax");
31} catch (Exception $e) {
32    echo $e::class, ': ', $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::class, ': ', $e->getMessage(), "\n";
43}
44
45try {
46    new DateTimeZone("GottaFindThisOne");
47} catch (DateInvalidTimeZoneException $e) {
48    echo $e::class, ': ', $e->getMessage(), "\n";
49}
50
51$p = new _p;
52try {
53    var_dump($p->getStartDate());
54} catch (Error $e) {
55    echo $e::class, ': ', $e->getMessage(), "\n";
56}
57try {
58    var_dump($p->getDateInterval());
59} catch (Error $e) {
60    echo $e::class, ': ', $e->getMessage(), "\n";
61}
62
63echo "DONE\n";
64?>
65--EXPECTF--
66string(19) "%d-%d-%d %d:%d:%d"
67DateObjectError: Object of type _d (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor
68DateMalformedStringException: Failed to parse time string (1am todax) at position 4 (t): The timezone could not be found in the database
69string(3) "UTC"
70DateObjectError: Object of type _t (inheriting DateTimeZone) has not been correctly initialized by calling parent::__construct() in its constructor
71DateInvalidTimeZoneException: DateTimeZone::__construct(): Unknown or bad timezone (GottaFindThisOne)
72DateObjectError: Object of type _p (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
73DateObjectError: Object of type _p (inheriting DatePeriod) has not been correctly initialized by calling parent::__construct() in its constructor
74DONE
75