Skip to content

Novis\Intl\RelativeTime::Unit

The unit of an amount of time that RelativeTime::format writes, such as "5 minutes ago".

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

Each item you pass to RelativeTime::format has a count and a unit. The unit is one of Second, Minute, Hour, Day, Week, Month, Quarter and Year. A negative count is in the past and a positive count is in the future, so { count: -2, unit: RelativeTime::Unit::Week } is "2 weeks ago".

The words and the plural form come from the locale.

Good to know: RelativeTime::format does not choose the unit for you. Your program decides whether 90 minutes is "1 hour ago" or "90 minutes ago".

Examples

Time since a post

<?nvs
// Shows the age of three posts, each with its own `RelativeTime::Unit`.
use Novis\Intl\RelativeTime;
// A negative count is in the past. A positive count is in the future.
array<string> $ages = RelativeTime::format([
{ count: -5, unit: RelativeTime::Unit::Minute },
{ count: -2, unit: RelativeTime::Unit::Week },
{ count: 1, unit: RelativeTime::Unit::Quarter },
], 'en');
echo Core\Str::join($ages, "\n"), "\n";
Output
5 minutes ago
2 weeks ago
in 1 quarter