chronify
v1.1.0
Published
Chronify calculates and displays human-readable time differences between dates, with customizable formats.
Downloads
12
Maintainers
Readme
∆ Chronify
Chronify
is a Node.js package that provides a simple way to calculate and display human-readable time differences between dates. Perfect for applications that need to show elapsed or remaining time in a user-friendly format.
Features
- Flexible Time Units: Shows time differences in years, months, days, hours, and minutes.
- Customizable Output: Supports both full and abbreviated unit formats.
- Human-readable Format: Easy-to-understand phrases like "2 weeks ago" or "in 3 days."
Installation
Install Chronify
via npm:
npm install chronify
Usage
Import and use Chronify
in your Node.js project:
const { chronify } = require("chronify");
Example
Display the time difference from the current date:
console.log(chronify("2024-09-01T12:00:00Z"));
// Example Output: "2 weeks ago" (depending on the current date)
Customizing Output
Control the number of units displayed and use abbreviated formats:
console.log(chronify("2024-09-01T12:00:00Z", { maxUnits: 1, short: true }));
// Example Output: "2w ago" (depending on the current date)
Options
maxUnits
(number): Maximum number of time units to display. Defaults to2
.short
(boolean): Use abbreviated units iftrue
. Defaults tofalse
.