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