2.4.0 • Published 4 months ago

react-timeago-i18n v2.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-timeago-i18n

build npm version npm bundle size

šŸ“…šŸŒ A tiny relative time component for react, which uses the browser's native Intl.RelativeTimeFormat API. This means that all languages are supported without bundling translations.

This library is 0.8 kB, which is significantly smaller than react-timeago which is 96 kB.

Install

npm install react-timeago-i18n

Usage

import TimeAgo from "react-timeago-i18n";

<TimeAgo date="2019-07-16" /> // --> "4 years ago"
<TimeAgo date="2019-07-16" locale="de-AT" /> // --> "vor 4 Jahren"

Props

PropertyDescriptionDefault Value
datestring or Date-
localethe language to usenavigator.language
formatOptionsoptions for Intl.RelativeTimeFormatundefined
allowFutureBy default, only dates in the past are supported. If you want to display future dates (i.e. "in 3 days") set this property to truefalse
hideSecondsBy default, values smaller than 1 minute will shown as "1 minute" instead of frequently updating seconds, unless you set this property to false.true
hideSecondsTextWhen using hideSeconds, seconds are displayed as "1 minute ago" or "in 1 minute", use this property to provide custom strings i.e. ["just now", "right now"][]
roundStrategyBy default, values are rounded (e.g. 11.9 months becomes "2 years"). If this is not desired, the rounding strategy can be changed to floor."round"
timeElementBy default, the result is wrapped in <time title="..."> ... </time>, unless you set this property to falsetrue

Context Provider

Options can be specified as props, or using a context provider.

For example:

import TimeAgo, { TimeAgoProvider } from "react-timeago-i18n";

<TimeAgoProvider locale="zh-Hans" hideSeconds>
  ...
  <TimeAgo date="2019-07-16" />
  ...
</TimeAgoProvider>;
2.3.0

8 months ago

2.4.0

4 months ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago