# react-relative-time

> React Component for rendering relative dates as HTML5 elements

Latest version **0.0.9** (published 2023-09-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-relative-time
pnpm add react-relative-time
yarn add react-relative-time
bun add react-relative-time
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2023-09-02 |
| First published | 2017-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Harsha Alva |
| Maintainers | aharshac, rlancer |
| Keywords | react, react-component, time, component, relative-time |

## Links

- npm: https://www.npmjs.com/package/react-relative-time
- Repository: https://github.com/aharshac/react-relative-time
- Homepage: https://github.com/aharshac/react-relative-time#readme
- Issues: https://github.com/aharshac/react-relative-time/issues
- npm.io page: https://npm.io/package/react-relative-time

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2023-09-02
- 0.0.8 — 2023-09-01
- 0.0.7 — 2017-04-20
- 0.0.6 — 2017-04-20
- 0.0.5 — 2017-04-20
- 0.0.4 — 2017-04-20
- 0.0.3 — 2017-04-20
- 0.0.2 — 2017-04-20

## README

# React Relative Time

[![Collaborizm](https://img.shields.io/badge/Collaborizm-Join%20now-blue.svg)](https://www.collaborizm.com/) [![Build Status](https://travis-ci.org/aharshac/react-relative-time.svg?branch=master)](https://travis-ci.org/aharshac/react-relative-time)    

 [![NPM](https://nodei.co/npm/react-relative-time.png?mini=true)](https://nodei.co/npm/react-relative-time/)


React Component for rendering relative dates as `<time>` HTML5 element and preserving machine readable format in `datetime`
attribute.

Does not depend on [**moment.js**](https://github.com/moment/moment)

&nbsp;

## Acknowledgement
This module was inspired by a few awesome open source projects.
* [**moment.js**](https://github.com/moment/moment)
* [**react-time**](https://github.com/andreypopp/react-time)
* [**timeago**](http://timeago.yarp.com/)

&nbsp;

## Installation
```
npm install react-relative-time
```  

&nbsp;

## Usage

```jsx
import React from 'react'
import RelativeTime from 'react-relative-time'

class MyComponent extends React.Component {

  render() {
    let now = new Date()
    let wasDate = new Date("Thu Jul 18 2013 15:48:59 GMT+0400")
    return (
      <div>
        <p><RelativeTime value={1492630940000} titleFormat="YYYY/MM/DD HH:mm" /></p>
        <p><RelativeTime value="1970-01-01T00:00:00Z" titleformat="iso8601" /></p>
        <p><RelativeTime value={new Date(2017, 3, 19, 22, 33, 44, 666)} /></p>
      </div>
    )
  }
}
```

&nbsp;

## Reference
### Attribute `value`
The input date and time, which will be displayed in relative terms to the present date and time.

Supported types:
* *Date* object   
  `new Date(2017, 3, 19, 22, 33, 44, 666)`

* *number* - UNIX timestamp in milliseconds   
  `1492630940000`

* *string* - ISO-8601 date string   
  `1970-01-01T00:00:00Z`

### Attribute `titleFormat`
The specifier for the date and time format to be shown in the `title` attribute.    
Default: `iso8601`.

Supported formats:
* `iso8601` - ISO-8601 date string
* *Custom string placeholders*.   
  Replaces with numbered date/time. Text like "Sunday", "Mon", etc. are not supported.   
  Ex: `YYYY/MM/DD HH:mm`    

Supported number placeholders:
```
M = month
D = date
H = hour
m = minute
s = second
```

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