tims
v2.1.0
Published
Textual display of millisecond durations and in several languages.
Downloads
180
Maintainers
Readme
Tims 🕚
Textual display of millisecond durations and in several languages.
Tims is not a converter and is not intended to be precise. It only converts milliseconds to a textual duration description. If you need to manage dates accurately, use dayjs instead.
- typescript typings included
- no dependency
- optimized and light code
Install
npm install tims@latest
Usage
Imports
// Typescript or ESModules
import tims from "tims"
// CommonJS
const tims = require("tims")
Example
Use for display uptime in Spanish
const startedAt = new Date()
function displayUptime() {
const uptimeText = tims.since(startedAt, { locale: "es" })
console.log(uptimeText)
}
Methods
since( moment, options ): string
Get the sentence of time past since given moment
between( moment, moment, options ): string
Get the sentence of time between given moments
duration( duration, options ): string
Get the sentence of given duration
Options
interface Options {
format?: "day" | "year" | "month" | "hour" | "minute" | "second" | "ms"
locale?: "fr" | "es" | "en"
full?: boolean
}