tims
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Tims 🕚

NPM

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
}

Enjoy 🕛

Package Sidebar

Install

npm i tims

Weekly Downloads

15

Version

2.1.0

License

MIT

Unpacked Size

10.7 kB

Total Files

10

Last publish

Collaborators

  • ghom