1.0.0 • Published 1 year ago

ngx-time-since v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Ngx-Time-Since

Ngx-Time-Since is an npm package that contains a single Angular Pipe. time-since pipe transforms a Date or String date value into a string value expressing the amount of time that has passed since the date.

Usage

Import the TimeSincePipe into your component.

import { TimeSincePipe } from 'ngx-time-since';

// code omiited for brevity...
imports: [
  TimeSincePipe,
]

Add the pipe to your template variables:

<span>{{ someDistantDate | timeSince }}</span>
<span>{{ "Wed, 21 Jul 2022 05:00:09 GMT" | timeSince }}</span>

Since the output is a string, you can chain additional string pipes to format the text in accordance with your wishes.

<span>{{ someDate | timeSince | titlecase }}</span>

This would transform the output from 8 months ago to 8 Months Ago.

Output

DifferenceMessage
< 1 minutea few moments ago
1 to 2 minutes1 minute ago
2 to 59 minutesX minutes ago
1 to 2 hours1 hour ago
2 to 23 hoursX hours ago
1 to 2 days1 day ago
2 to 6 daysX days ago
1 to 2 weeks1 week ago
2 to 4 weeksX weeks ago
1 to 2 months1 month ago
2 to 12 monthsX months ago
1 to 2 years ago1 year ago
>= 2 years agoX years ago

Testing

Each outcome has been tested via a unit test.