# @yaireo/relative-time

> javascript function to transform timestamp or date to local relative-time

Latest version **1.1.0** (published 2025-08-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @yaireo/relative-time
pnpm add @yaireo/relative-time
yarn add @yaireo/relative-time
bun add @yaireo/relative-time
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

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

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-08-09 |
| First published | 2021-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 42 |
| Author | Yair Even-Or |
| Maintainers | vsync |
| Keywords | relative time, date, timestamp, javascript, js, local, locale |

## Links

- npm: https://www.npmjs.com/package/@yaireo/relative-time
- Repository: https://github.com/yairEO/relative-time
- Issues: https://github.com/yaireo/relative-time/issues
- npm.io page: https://npm.io/package/@yaireo/relative-time

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2025-08-09
- 1.0.5 — 2024-09-13
- 1.0.4 — 2023-07-06
- 1.0.3 — 2023-02-19
- 1.0.2 — 2022-04-04
- 1.0.1 — 2021-04-10
- 1.0.0 — 2021-04-10

## README

<p align="center">
  <a title='See demo' href="https://jsbin.com/vokawun/edit?html,js,console">
    <img  src="readme-header.svg"/ >
  </a>
</p>
<h3 align="center">Transform timestamp or date to local relative-time</h3>

---
<p align="center">
Super lightweight (<strong><code title='minified'>< 500 bytes</code></strong>) &nbsp; <big>🕙</big> &nbsp; Uses <a title='MDN docs for Intl.RelativeTimeFormat' href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat'>native browser API</a>
</p>
<br>

## Install:

[NPM](https://www.npmjs.com/package/@yaireo/relative-time) / [CDN](https://unpkg.com/@yaireo/relative-time) / Download from this repo

```bash
npm i @yaireo/relative-time -S
```

## Usage:

Import:

```js
import RelativeTime from '@yaireo/relative-time'

And use:

```js
const relativeTime = new RelativeTime(); // defaults to OS locale
const relativeTimeSpanish = new RelativeTime({ locale: 'es' }); // set Spanish locale

console.log(   relativeTime.from(new Date('2020'))  )  // "6 years ago"
console.log(   relativeTimeSpanish.from(new Date('2020'))  )  // "hace 6 años"
```

Or without instanciation:

```js
console.log(RelativeTime.from(new Date('2032'))) // "in 6 years"
```

[Live demo](https://jsbin.com/vokawun/edit?html,js,console)

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