npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dotiw

v1.0.4

Published

DOTIW (distance of time in words) helps returns relatively human readable timestamps

Downloads

9

Readme

DOTIW

DOTIW (distance of time in words) helps returns relatively human readable timestamps

Installation

npm i dotiw

usage

const dotiw = require('dotiw')
const { distance } = dotiw(startDate, endDate)

Examples

dotiw will return an object with distance as a string, you can directly use the distance string or use the data provided by the obect to modify the string according to your need.

Years

About 1 year

const result = dotiw("2021-01-01 00:00:00", "2022-01-01 00:00:00")

output => { years: 1,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '1 year',
            prefix: '',
            distance: '1 year',
            suffix: 'from now' }

About x years

const result = dotiw("2019-12-15 00:00:00", "2022-01-01 00:00:00")

output => { years: 2,
            months: 0,
            weeks: 2,
            days: 4,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '2 years',
            prefix: 'about',
            distance: 'about 2 years',
            suffix: 'later' }
const result = dotiw("2025-01-01 00:00:00", "2022-01-18 00:00:00")
output => { years: 2,
            months: 11,
            weeks: 2,
            days: 5,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '3 year',
            prefix: 'less than',
            distance: 'less than 3 years ago',
            suffix: 'ago' }

Months

x months

const result = dotiw("2022-03-01 00:00:00", "2022-01-01 00:00:00")

output => { years: 0,
            months: 1,
            weeks: 4,
            days: 1,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '2 months',
            prefix: '',
            distance: '2 month ago',
            suffix: 'ago' }

About x months

const result = dotiw("2022-03-01 00:00:00", "2022-01-19 00:00:00")

output = { years: 0,
            months: 1,
            weeks: 1,
            days: 4,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '1 month',
            prefix: 'about',
            distance: 'about 1 month ago',
            suffix: 'ago' }

More than x months

const result = dotiw("2022-03-01 00:00:00", "2022-01-18 00:00:00")

output => { years: 0,
            months: 1,
            weeks: 1,
            days: 5,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '1 month',
            prefix: 'more than',
            distance: 'more than 1 month ago',
            suffix: 'ago' }

Less than x months

const result = dotiw("2022-03-01 00:00:00", "2022-01-12 00:00:00")
output => { years: 0,
            months: 1,
            weeks: 2,
            days: 4,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '2 months',
            prefix: 'less than',
            distance: 'less than 2 months ago',
            suffix: 'ago' }

weeks

x weeks

const result = dotiw("2022-01-01 00:00:00", "2022-01-15 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 2,
            days: 0,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '2 weeks',
            prefix: '',
            distance: '2 weeks',
            suffix: 'later' }

More than x weeks

const result = dotiw("2022-01-01 00:00:00", "2022-01-18 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 2,
            days: 3,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '2 weeks',
            prefix: 'more than',
            distance: 'more than 2 weeks',
            suffix: 'later' }

About x weeks

const result = dotiw("2022-01-01 00:00:00", "2022-01-21 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 2,
            days: 6,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '3 weeks',
            prefix: 'about',
            distance: 'about 3 weeks',
            suffix: 'later'}

Less than x weeks

const result = dotiw("2022-01-01 00:00:00", "2022-01-28 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 3,
            days: 6,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '4 weeks',
            prefix: 'less than',
            distance: 'less than a month',
            suffix: 'later' }

Days

x days

const result = dotiw("2022-01-01 00:00:00", "2022-01-06 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 5,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '5 days',
            prefix: 'about',
            distance: 'less than a week',
            suffix: 'later' }

About x days

const result = dotiw("2022-01-01 00:00:00", "2022-01-07 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 6,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '1 week',
            prefix: 'about',
            distance: 'about 1 week',
            suffix: 'later' }
const result = dotiw("2022-01-01 00:00:00", "2022-01-03 00:00:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 2,
            hours: 0,
            minutes: 0,
            seconds: 0,
            value: '2 day',
            prefix: '',
            distance: '2 day',
            suffix: 'later' }

hours

const result = dotiw("2022-01-01 00:00:00", "2022-01-01 23:00:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 23,
            minutes: 0,
            seconds: 0,
            value: '1 day',
            prefix: 'about',
            distance: 'about 1 day',
            suffix: 'later' }
const result = dotiw("2022-01-01 00:00:00", "2022-01-01 03:00:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 23,
            minutes: 0,
            seconds: 0,
            value: '3 hours',
            prefix: '',
            distance: '3 hours',
            suffix: 'later' }

minutes

const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:10:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 10,
            seconds: 0,
            value: '10 minutes',
            prefix: '',
            distance: '10 minutes',
            suffix: 'later' }
const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:10:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 10,
            seconds: 0,
            value: '10 minutes',
            prefix: '',
            distance: '10 minutes',
            suffix: 'later' }
const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:50:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 50,
            seconds: 0,
            value: '1 hour',
            prefix: 'less than',
            distance: 'less than 1 hour',
            suffix: 'later' }
const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:55:00")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 55,
            seconds: 0,
            value: '1 hour',
            prefix: '',
            distance: 'about 1 hour',
            suffix: 'later' }

Seconds

dotiw will provide starting 10 seconds as it is. Rest of the seconds are rounded off

const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:00:10")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 0,
            seconds: 10,
            value: '10 seconds',
            prefix: '',
            distance: 'about 10 seconds',
            suffix: 'later' }

10 - 20 ===> about 20 seconds, you can always cutomize the message with the values provided

const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:00:17")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 0,
            seconds: 17,
            value: '20 seconds',
            prefix: '',
            distance: 'about 20 seconds',
            suffix: 'later' }
const result = dotiw("2022-01-01 00:00:00", "2022-01-01 00:00:55")
output => { years: 0,
            months: 0,
            weeks: 0,
            days: 0,
            hours: 0,
            minutes: 0,
            seconds: 55,
            value: '1 minute',
            prefix: 'about',
            distance: 'about a minute',
            suffix: 'later' }