1 import { Pipe, PipeTransform } from '@angular/core';
7 export class DurationPipe implements PipeTransform {
9 * Translates seconds into human readable format of seconds, minutes, hours, days, and years
10 * source: https://stackoverflow.com/a/34270811
12 * @param {number} seconds The number of seconds to be processed
13 * @return {string} The phrase describing the the amount of time
15 transform(seconds: number): string {
17 [`${Math.floor(seconds / 31536000)}`, 'years'],
18 [`${Math.floor((seconds % 31536000) / 86400)}`, 'days'],
19 [`${Math.floor((seconds % 86400) / 3600)}`, 'hours'],
20 [`${Math.floor((seconds % 3600) / 60)}`, 'minutes'],
21 [`${Math.floor(seconds % 60)}`, 'seconds']
25 for (let i = 0, max = levels.length; i < max; i++) {
26 if (levels[i][0] === '0') {
33 (levels[i][0] === '1' ? levels[i][1].substr(0, levels[i][1].length - 1) : levels[i][1]);
35 return returntext.trim() || '1 second';