Skip to content

Commit c6bd988

Browse files
committed
Fix #78649 Provide ICU RELATIVE_ constants
1 parent 85ea04b commit c6bd988

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

ext/intl/dateformat/dateformat.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ void dateformat_register_constants( INIT_FUNC_ARGS )
4444
DATEFORMATTER_EXPOSE_CLASS_CONST( MEDIUM );
4545
DATEFORMATTER_EXPOSE_CLASS_CONST( SHORT );
4646
DATEFORMATTER_EXPOSE_CLASS_CONST( NONE );
47+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_FULL", UDAT_FULL_RELATIVE );
48+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_LONG", UDAT_LONG_RELATIVE );
49+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_MEDIUM", UDAT_MEDIUM_RELATIVE );
50+
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "RELATIVE_SHORT", UDAT_SHORT_RELATIVE );
4751

4852
/*
4953
DATEFORMATTER_EXPOSE_CUSTOM_CLASS_CONST( "GREGORIAN", DATEF_GREGORIAN );
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
printFormat(IntlDateFormatter::RELATIVE_FULL, IntlDateFormatter::NONE, getDayInPast());
24+
printFormat(IntlDateFormatter::RELATIVE_LONG, IntlDateFormatter::NONE, getDayInPast());
25+
printFormat(IntlDateFormatter::RELATIVE_MEDIUM, IntlDateFormatter::NONE, getDayInPast());
26+
printFormat(IntlDateFormatter::RELATIVE_SHORT, IntlDateFormatter::NONE, getDayInPast());
27+
28+
function 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+
40+
function getToday(): DateTimeImmutable {
41+
return new DateTimeImmutable();
42+
}
43+
44+
function getYesterday(): DateTimeImmutable {
45+
return new DateTimeImmutable("-1 day");
46+
}
47+
48+
function getTomorrow(): DateTimeImmutable {
49+
return new DateTimeImmutable("+1 day");
50+
}
51+
52+
function getDayInPast(): DateTimeImmutable {
53+
return new DateTimeImmutable("2020-01-20 20:20:20", new DateTimeZone("UTC"));
54+
}
55+
56+
--EXPECT--
57+
yesterday
58+
yesterday
59+
yesterday
60+
yesterday
61+
today
62+
today
63+
today
64+
today
65+
tomorrow
66+
tomorrow
67+
tomorrow
68+
tomorrow
69+
Monday, January 20, 2020
70+
January 20, 2020
71+
Jan 20, 2020
72+
1/20/20

0 commit comments

Comments
 (0)