Last active
May 14, 2017 08:08
-
-
Save enif-lee/662075ed197e27c3b6deef811597b09d to your computer and use it in GitHub Desktop.
Last connected time pipe for angular
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Pipe, PipeTransform } from '@angular/core'; | |
@Pipe({ name: 'lastConnectedFormat' }) | |
export class LastConnectedTimeFormatPipe implements PipeTransform { | |
transform(connectedTime: Date, ...args): string { | |
let elapsed = new Date(new Date().getTime() - connectedTime.getTime()).getTime() / 60000; | |
let time: string = ''; | |
if (elapsed < 60) { | |
time = 'minutes ago'; | |
} else if ((elapsed /= 60) < 24) { | |
time = 'hours ago'; | |
} else if ((elapsed /= 24) < 30) { | |
time = 'days ago'; | |
} else return 'no connect'; | |
return Math.round(elapsed) + time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment