Skip to content

Novis\Intl\Width

How short RelativeTime::format and ListFormat::join make their text.

You pass a Width as width:

  • Wide writes every word in full: "3 months ago" and "Shop, Blog, and Wiki". This is the default.
  • Short uses short forms: "3 mo. ago" and "Shop, Blog, & Wiki".
  • Narrow uses the shortest forms: "3mo ago" and "Shop, Blog, Wiki".

Use Short or Narrow where space is small, such as on a phone screen or in a table column.

Good to know: in some locales, two widths give the same text.

Examples

Wide short narrow

<?nvs
// Shows how `Width` makes a relative time and a list shorter, for a small screen.
use Novis\Intl\ListFormat;
use Novis\Intl\RelativeTime;
use Novis\Intl\Width;
array<Width> $widths = [Width::Wide, Width::Short, Width::Narrow];
foreach ($widths as Width $width) {
string $age = RelativeTime::format([{ count: -3, unit: RelativeTime::Unit::Month }], 'en', { width: $width })[0];
string $list = ListFormat::join([['Shop', 'Blog', 'Wiki']], 'en', { width: $width })[0];
echo $age, ' | ', $list, "\n";
}
Output
3 months ago | Shop, Blog, and Wiki
3 mo. ago | Shop, Blog, & Wiki
3mo ago | Shop, Blog, Wiki