0.1.2 • Published 2 years ago

once-upon-a-pipe v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

OnceUponAPipe

once-upon-a-pipe is a simple Angular pipe for converting a date string into a time ago or a time from now.


Time RangePast TimeFuture Time
0 - 29 secondsjust nowX seconds from now
30 - 60 seconds1 minute ago1 minute from now
1 - 45 minutesX minutes agoX minutes from now
45 - 90 minutes1 hour ago1 hour from now
90 minutes - 22 hoursX hours agoX hours from now
22 - 36 hours1 day ago1 day from now
36 hours - 25 daysX days agoX days from now
25 - 45 days1 month ago1 month from now
45 - 345 daysX months agoX months from now
345 - 545 days (1.5 years)1 year ago1 year from now
546 days+X years agoX years from now

Installation

npm i once-upon-a-pipe --save

Usage

You need to import the OnceUponAPipeModule by adding the following lines to your app.module.ts file.

import { OnceUponAPipeModule } from 'once-upon-a-pipe';

@NgModule({
  imports: [OnceUponAPipeModule]
})

export class AppModule { }

In your component templates you can just do:

<p>{{ my_date | onceUponAPipe}}</p>

where my_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.