🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

relative-time-format

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

relative-time-format

A convenient Intl.RelativeTimeFormat polyfill

1.1.6
latest
Source
npm
Version published
Maintainers
1
Created

What is relative-time-format?

The 'relative-time-format' npm package is used to format dates and times relative to the current date and time. It provides a way to display time differences in a human-readable format, such as '2 days ago' or 'in 3 hours'. This is particularly useful for applications that need to display time-related information in a user-friendly manner.

What are relative-time-format's main functionalities?

Basic Relative Time Formatting

This feature allows you to format a time difference in a human-readable way. The example shows how to format '1 day ago' and 'in 2 days' using the 'relative-time-format' package.

const RelativeTimeFormat = require('relative-time-format');
const rtf = new RelativeTimeFormat('en', { numeric: 'auto' });
console.log(rtf.format(-1, 'day')); // 'yesterday'
console.log(rtf.format(2, 'day')); // 'in 2 days'

Customizing Locale

This feature allows you to customize the locale for the relative time format. The example shows how to format the time difference in French.

const RelativeTimeFormat = require('relative-time-format');
const rtf = new RelativeTimeFormat('fr', { numeric: 'auto' });
console.log(rtf.format(-1, 'day')); // 'hier'
console.log(rtf.format(2, 'day')); // 'dans 2 jours'

Using Different Units

This feature allows you to use different units such as 'hour' and 'minute' for formatting the time difference. The example shows how to format 'an hour ago' and 'in 3 minutes'.

const RelativeTimeFormat = require('relative-time-format');
const rtf = new RelativeTimeFormat('en', { numeric: 'auto' });
console.log(rtf.format(-1, 'hour')); // 'an hour ago'
console.log(rtf.format(3, 'minute')); // 'in 3 minutes'

Other packages similar to relative-time-format

Keywords

relative

FAQs

Package last updated on 02 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts