1--TEST--
2datefmt_format_code() with relative formats
3--SKIPIF--
4<?php if (!extension_loaded("intl")) print "skip"; ?>
5--FILE--
6<?php
7
8printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getYesterday());
9printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getYesterday());
10printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getYesterday());
11printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getYesterday());
12
13printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getToday());
14printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getToday());
15printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getToday());
16printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getToday());
17
18printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getTomorrow());
19printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getTomorrow());
20printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getTomorrow());
21printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getTomorrow());
22
23printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getDayInPast());
24printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getDayInPast());
25printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getDayInPast());
26printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getDayInPast());
27
28function printFormat(int $dateFormat, int $timeFormat, DateTimeImmutable $time) {
29    $formatter = new IntlDateFormatter(
30        "en_US",
31        $dateFormat,
32        $timeFormat,
33        "America/Los_Angeles",
34        IntlDateFormatter::GREGORIAN
35    );
36
37    echo $formatter->format($time) . "\n";
38}
39
40function getToday(): DateTimeImmutable {
41    return new DateTimeImmutable();
42}
43
44function getYesterday(): DateTimeImmutable {
45    return new DateTimeImmutable("-1 day");
46}
47
48function getTomorrow(): DateTimeImmutable {
49    return new DateTimeImmutable("+1 day");
50}
51
52function getDayInPast(): DateTimeImmutable {
53    return new DateTimeImmutable("2020-01-20 20:20:20", new DateTimeZone("UTC"));
54}
55
56?>
57--EXPECT--
58yesterday
59yesterday
60yesterday
61yesterday
62today
63today
64today
65today
66tomorrow
67tomorrow
68tomorrow
69tomorrow
70Monday, January 20, 2020
71January 20, 2020
72Jan 20, 2020
731/20/20
74