# s-ago

> Human readable relative times (eg. 4 minutes ago)

Latest version **2.2.0** (published 2020-06-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install s-ago
pnpm add s-ago
yarn add s-ago
bun add s-ago
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2020-06-03 |
| First published | 2015-08-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 87.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 97 |
| Author | sebastian sandqvist |
| Maintainers | seabass |
| Keywords | relative, date, time, ago, timestamp, format |

## Links

- npm: https://www.npmjs.com/package/s-ago
- Repository: https://github.com/sebastiansandqvist/s-ago
- Issues: https://github.com/sebastiansandqvist/s-ago/issues
- npm.io page: https://npm.io/package/s-ago

## Alternatives

- [@js-joda/timezone](https://npm.io/package/@js-joda/timezone.md) — 383.4K weekly downloads
- [chartjs-adapter-moment](https://npm.io/package/chartjs-adapter-moment.md) — 210.8K weekly downloads
- [strftime](https://npm.io/package/strftime.md) — 171.2K weekly downloads
- [vue-flatpickr-component](https://npm.io/package/vue-flatpickr-component.md) — 115.8K weekly downloads
- [timepicker](https://npm.io/package/timepicker.md) — 51.0K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2020-06-03
- 2.1.0 — 2019-08-18
- 2.0.1 — 2018-09-08
- 2.0.0 — 2018-09-08
- 1.3.0 — 2018-07-21
- 1.2.2 — 2018-01-26
- 1.2.1 — 2018-01-26
- 1.2.0 — 2018-01-24
- 1.1.0 — 2016-05-24
- 1.0.6 — 2015-09-02
- 1.0.5 — 2015-09-02
- 1.0.4 — 2015-09-02
- 1.0.3 — 2015-09-02
- 1.0.2 — 2015-08-30
- 1.0.1 — 2015-08-30
- … 1 more at https://npm.io/package/s-ago/versions

## README

# s-ago

[![NPM version](https://img.shields.io/npm/v/s-ago.svg)](https://www.npmjs.com/package/s-ago) ![Dependencies](https://img.shields.io/david/sebastiansandqvist/s-ago.svg) [![build status](http://img.shields.io/travis/sebastiansandqvist/s-ago.svg)](https://travis-ci.org/sebastiansandqvist/s-ago) [![NPM license](https://img.shields.io/npm/l/s-ago.svg)](https://www.npmjs.com/package/s-ago)

This is the smallest, fully unit tested module to convert Date objects into human readable relative timestamps, such as `'4 minutes ago'`, `'yesterday'`, `'tomorrow'`, or `'in 3 months'`. All in 22 lines of TypeScript.

You can optionally specify the maximum unit (eg. `hour`, `day`, `week`) so instead of outputting `'2 weeks ago'` you will see `'14 days ago'`.

## Usage
```javascript
var ago = require('s-ago');

var now = new Date();
var yesterday = new Date(now.getTime() - (24 * 60 * 60 * 1000));
var hoursAgo = new Date(now.getTime() - (6 * 60 * 60 * 1000));
var yesterday = new Date(now.getTime() - (24 * 60 * 60 * 1000));
var tomorrow = new Date(now.getTime() + (6 * 60 * 60 * 1000));
var inSixHours = new Date(now.getTime() + (6 * 60 * 60 * 1000));
var inTwoWeeks = new Date(now.getTime() + (2 * 7 * 24 * 60 * 60 * 1000));

// present
ago(now); // 'just now'

// past
ago(yesterday); // 'yesterday'
ago(hoursAgo); // '6 hours ago'

// future
ago(inSixHours); // 'in 6 hours'
ago(tomorrow); // 'tomorrow'

// max unit
ago(inTwoWeeks);  // 'in 2 weeks'
ago(inTwoWeeks, 'day'); // 'in 14 days'
```

Output is as follows:

Time | Output | Future output
--- | --- | ---
Less than 1 minute | `just now` | `just now`
1-2 minutes | `a minute ago` | `in a minute`
2-46 minutes | `# minutes ago` | `in # minutes`
46 minutes - 2 hours | `an hour ago` | `in an hour`
2-20 hours | `# hours ago` | `in # hours`
20-48 hours | `yesterday` | `tomorrow`
2-6 days | `last week` | `in a week`
7-28 days | `# weeks ago` | `in # weeks`
28 days - 2 months | `last month` | `in a month`
2-11 months | `# months ago` | `in # months`
11-23 months | `last year` | `in a year`
2+ years | `# years ago` | `in # years`

---
_Source: https://npm.io/package/s-ago · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
