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