Joining lists, formatting ranges, and directed ("relative") durations. As of
PHP v3 these all work in every port — PHP reconstructs the few formatters
ext-intl doesn't bind from live CLDR data (with two small caveats, noted below).
Join items with the locale's list conventions. Available in all four ports.
consten=newCosmo("en");en.join(["A","B","C"]);// "A, B, and C"en.join(["A","B","C"],"disjunction");// "A, B, or C"newCosmo("es").join(["uno","dos","tres"]);// "uno, dos y tres"
Cosmoen=newCosmo("en");en.join(List.of("A","B","C"));// "A, B, and C"en.join(List.of("A","B","C"),"disjunction");// "A, B, or C"newCosmo("es").join(List.of("uno","dos","tres"));// "uno, dos y tres"
$en=newCosmo('en');$en->join(['A','B','C']);// "A, B, and C"$en->join(['A','B','C'],'disjunction');// "A, B, or C"newCosmo('es')->join(['uno','dos','tres']);// "uno, dos y tres"
en=Cosmo("en")en.join(["A","B","C"])# "A, B, and C"en.join(["A","B","C"],"disjunction")# "A, B, or C"Cosmo("es").join(["uno","dos","tres"])# "uno, dos y tres"
Type: conjunction (and, default), disjunction (or), or unit.
A directed duration carries a past/future orientation — the counterpart of the
undirected duration().
constc=newCosmo("en");c.relativeDuration(-3,"day");// "3 days ago"c.relativeDuration(2,"hour");// "in 2 hours"c.relativeDuration(-1,"day","auto");// "yesterday"c.relativeDurationBetween(target,reference);// e.g. "in 5 days"
Cosmoc=newCosmo("en");c.relativeDuration(-3,"day");// "3 days ago"c.relativeDuration(2,"hour");// "in 2 hours"c.relativeDuration(-1,"day","auto");// "yesterday"c.relativeDurationBetween(target,reference);// e.g. "in 5 days"
$c=newCosmo('en');$c->relativeDuration(-3,'day');// "3 days ago"$c->relativeDuration(2,'hour');// "in 2 hours"$c->relativeDuration(-1,'day','auto');// "yesterday" (word form)$c->relativeDurationBetween($target,$reference);// e.g. "in 5 days"
c=Cosmo("en")c.relative_duration(-3,"day")# "3 days ago"c.relative_duration(2,"hour")# "in 2 hours"c.relative_duration(-1,"day","auto")# "1 day ago" (numeric — see note)c.relative_duration_between(target,reference)# e.g. "in 5 days"
One Python nuance
relativeDuration / relativeDurationBetween are now in all four ports.
ICU/Intl produce single-unit relative text only (no "3 days, 5 hours
ago"). The numeric: "auto" word-forms ("yesterday", "last week") work in PHP,
JavaScript, and Java; Python falls back to the numeric form ("1 day ago")
because PyICU doesn't cleanly expose them — always correct, just not colloquial.
For an undirected span, use duration().