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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@chaisser/human-time

v1.0.1

Published

Human readable time formatter - '2 hours ago', 'in 3 days', 'just now'

Readme

⏰ @chaisser/human-time

Human-readable time formatting: "2 hours ago", "in 3 days", "just now" — with English and Turkish support


✨ Features

  • 🎯 Type-safe - Full TypeScript support
  • 🌍 Multi-locale - English and Turkish labels
  • 📅 Relative time - Format dates as "3 days ago" or "in 2 hours"
  • ⏱️ Durations - Format milliseconds as "5 minutes", "2 hours"
  • 🔧 Formatters - Pre-configured formatter factories
  • 🕐 Flexible input - Accepts Date, timestamp number, or ISO string
  • 🪶 Zero dependencies - Lightweight and tree-shakeable
  • 🏎️ ESM + CJS - Dual module format support

📦 Installation

npm install @chaisser/human-time
# or
yarn add @chaisser/human-time
# or
pnpm add @chaisser/human-time

🚀 Quick Start

import { humanTime, timeAgo, timeIn, duration, createFormatter } from '@chaisser/human-time';

// Relative time from now
humanTime(new Date(Date.now() - 5000));    // "5 seconds ago"
humanTime(new Date(Date.now() + 3600000)); // "in 1 hour"

// Shorthand functions
timeAgo(new Date(Date.now() - 86400000));  // "1 day ago"
timeIn(new Date(Date.now() + 7200000));    // "in 2 hours"

// Duration formatting
duration(1500);    // "1 second"
duration(7200000); // "2 hours"

// Turkish locale
humanTime(new Date(Date.now() - 3600000), { locale: 'tr' }); // "1 saat önce"

📖 What It Does

This package converts dates and durations into human-readable strings. It calculates the difference between a target date and now, then expresses it in natural language — supporting past ("ago") and future ("in") tenses. It also formats millisecond durations and supports English and Turkish locales.


🎯 How It Works

The package provides 5 functions:

  • humanTime - Format any date relative to now (past or future)
  • timeAgo - Alias for humanTime, emphasizes past dates
  • timeIn - Alias for humanTime, emphasizes future dates
  • duration - Format a millisecond duration as a human string
  • createFormatter - Create a pre-configured formatter function

Time units used: seconds, minutes, hours, days, weeks, months, years.


🎨 What It's Useful For

  • Activity Feeds - "posted 5 minutes ago"
  • Notifications - "meeting in 2 hours"
  • Chat Apps - Message timestamps
  • Dashboards - Last updated indicators
  • Countdowns - "in 3 days"
  • Logging - Human-readable elapsed time
  • Internationalization - Turkish and English support

💡 Usage Examples

Relative Time

import { humanTime } from '@chaisser/human-time';

const now = Date.now();

humanTime(new Date(now - 30000));      // "30 seconds ago"
humanTime(new Date(now - 300000));     // "5 minutes ago"
humanTime(new Date(now - 7200000));    // "2 hours ago"
humanTime(new Date(now - 86400000));   // "1 day ago"
humanTime(new Date(now - 604800000));  // "1 week ago"

humanTime(new Date(now + 60000));      // "in 1 minute"
humanTime(new Date(now + 3600000));    // "in 1 hour"
humanTime(new Date(now + 86400000));   // "in 1 day"
humanTime(new Date(now + 2592000000)); // "in 1 month"

// Under 1 second
humanTime(new Date(now - 500));        // "just now"

Flexible Input Types

// Date object
humanTime(new Date('2024-01-01'));

// Timestamp number
humanTime(Date.now() - 3600000); // "1 hour ago"

// ISO string
humanTime('2024-01-01T00:00:00Z');

Duration Formatting

import { duration } from '@chaisser/human-time';

duration(500);        // "500ms"
duration(1000);       // "1 second"
duration(45000);      // "45 seconds"
duration(120000);     // "2 minutes"
duration(7200000);    // "2 hours"
duration(172800000);  // "2 days"

Turkish Locale

humanTime(new Date(Date.now() - 3600000), { locale: 'tr' });
// "1 saat önce"

humanTime(new Date(Date.now() + 86400000), { locale: 'tr' });
// "1 gün sonra"

duration(120000, { locale: 'tr' });
// "2 dakika"

Fixed Reference Time

// Useful for deterministic tests
const referenceTime = new Date('2024-06-15T12:00:00Z');

humanTime(new Date('2024-06-15T11:00:00Z'), { now: referenceTime });
// "1 hour ago"

humanTime(new Date('2024-06-15T14:30:00Z'), { now: referenceTime });
// "in 2 hours"

Pre-configured Formatter

import { createFormatter } from '@chaisser/human-time';

const trFormatter = createFormatter({ locale: 'tr' });
trFormatter(new Date(Date.now() - 86400000)); // "1 gün önce"

const relativeTo = createFormatter({ now: new Date('2024-01-01') });
relativeTo(new Date('2024-01-02')); // "in 1 day"

📚 API Reference

humanTime(date, options?)

Format a date relative to now.

| Parameter | Type | Description | |---|---|---| | date | Date \| number \| string | Target date | | options.locale | 'en' \| 'tr' | Language (default: 'en') | | options.now | Date | Reference time (default: new Date()) |

Returns: string — e.g. "3 hours ago", "in 2 days", "just now"

timeAgo(date, options?)

Alias for humanTime. Same parameters and return type.

timeIn(date, options?)

Alias for humanTime. Same parameters and return type.

duration(ms, options?)

Format a millisecond duration.

| Parameter | Type | Description | |---|---|---| | ms | number | Duration in milliseconds | | options.locale | 'en' \| 'tr' | Language (default: 'en') |

Returns: string — e.g. "5 minutes", "2 hours", "500ms"

createFormatter(options?)

Create a pre-configured formatter function.

| Parameter | Type | Description | |---|---|---| | options.locale | 'en' \| 'tr' | Language | | options.now | Date | Fixed reference time |

Returns: (date: Date \| number \| string) => string

Locale Labels

| Unit | English | Turkish | |---|---|---| | second(s) | second / seconds | saniye | | minute(s) | minute / minutes | dakika | | hour(s) | hour / hours | saat | | day(s) | day / days | gün | | week(s) | week / weeks | hafta | | month(s) | month / months | ay | | year(s) | year / years | yıl | | ago | ago | önce | | in | in | sonra | | just now | just now | şimdi |


🔗 Related Packages

Explore our other utility packages in the @chaisser namespace:


🔒 License

MIT - Free to use in personal and commercial projects


👨 Developed by

Doruk Karaboncuk [email protected]


📄 Repository


🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests
  • Improve documentation

📞 Support

For issues, questions, or suggestions, please reach out through:


Made with ❤️ by @chaisser

npm license downloads typescript