1.3.2 • Published 6 years ago

time-ago-pipe v1.3.2

Weekly downloads
8,425
License
MIT
Repository
github
Last release
6 years ago

time-ago-pipe

Build Status npm npm GitHub issues npm

A really simple, lightweight Angular pipe for converting a date string into a time ago

Time RangeOutput
0 - 45 secondsa few seconds ago
45 - 90 secondsa minute ago
90 seconds - 45 minutesX minutes ago
45 - 90 minutesan hour ago
90 minutes - 22 hoursX hours ago
22 - 36 hoursa day ago
36 hours - 25 daysX days ago
25 - 45 daysa month ago
45 - 345 daysX months ago
345 - 545 days (1.5 years)a year ago
546 days+X years ago

##Installation npm install time-ago-pipe --save

Usage

It can be imported into your angular project, as you would for any other library.

In the @NgModule you want to use it in

import {TimeAgoPipe} from 'time-ago-pipe';

add "TimeAgoPipe" to your declarations

@NgModule({
	imports: [... etc ...],
	declarations: [..., TimeAgoPipe, ... ]
})

In your component templates you can just do:

<span>{{your_date | timeAgo}}</span>

where "your_date" is a local date string, which could be parsed by the standard Js Date()

If this value is null or not parsable as a date, then the pipe will display nothing