Skip to content

Novis\Intl\RelativeTime::Numeric

Whether RelativeTime::format always writes a number, or uses a word such as "yesterday" where the language has one.

RelativeTime::Numeric is declared in the class Novis\Intl\RelativeTime.

You pass a RelativeTime::Numeric as numeric. Always, the default, writes "1 day ago", "in 0 days" and "in 1 day". Auto writes "yesterday", "today" and "tomorrow" for the same counts. For counts that have no word of their own, both write the number.

Auto reads more naturally on a page. Always gives the same pattern for every count, which is easier to compare in a list.

Examples

Yesterday or one day ago

<?nvs
// Shows the difference between `RelativeTime::Numeric::Always` and `RelativeTime::Numeric::Auto` for nearby days.
use Novis\Intl\RelativeTime;
array<{ count: int, unit: RelativeTime::Unit }> $days = [
{ count: -1, unit: RelativeTime::Unit::Day },
{ count: 0, unit: RelativeTime::Unit::Day },
{ count: 1, unit: RelativeTime::Unit::Day },
];
// `Always` is the default and always writes a number.
echo Core\Str::join(RelativeTime::format($days, 'en', { numeric: RelativeTime::Numeric::Always }), ' | '), "\n";
// `Auto` writes a word where the language has one.
echo Core\Str::join(RelativeTime::format($days, 'en', { numeric: RelativeTime::Numeric::Auto }), ' | '), "\n";
Output
1 day ago | in 0 days | in 1 day
yesterday | today | tomorrow