From 5f1caca5da0435681429326a0288ed1d087a694d Mon Sep 17 00:00:00 2001 From: davidcanonieto Date: Mon, 17 Jun 2019 14:16:48 +0100 Subject: [PATCH] [ADF-4677] Make time ago use Angular Date formats (#4856) --- lib/core/pipes/time-ago.pipe.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/core/pipes/time-ago.pipe.ts b/lib/core/pipes/time-ago.pipe.ts index b4c0ff0985..38694141f5 100644 --- a/lib/core/pipes/time-ago.pipe.ts +++ b/lib/core/pipes/time-ago.pipe.ts @@ -19,6 +19,7 @@ import moment from 'moment-es6'; import { Pipe, PipeTransform } from '@angular/core'; import { AppConfigService } from '../app-config/app-config.service'; import { UserPreferenceValues, UserPreferencesService } from '../services/user-preferences.service'; +import { DatePipe } from '@angular/common'; @Pipe({ name: 'adfTimeAgo' @@ -26,7 +27,7 @@ import { UserPreferenceValues, UserPreferencesService } from '../services/user-p export class TimeAgoPipe implements PipeTransform { static DEFAULT_LOCALE = 'en-US'; - static DEFAULT_DATE_TIME_FORMAT = 'DD/MM/YYYY HH:mm'; + static DEFAULT_DATE_TIME_FORMAT = 'dd/MM/yyyy HH:mm'; defaultLocale: string; defaultDateTimeFormat: string; @@ -44,7 +45,12 @@ export class TimeAgoPipe implements PipeTransform { const actualLocale = locale || this.defaultLocale; const then = moment(value); const diff = moment().locale(actualLocale).diff(then, 'days'); - return diff > 7 ? then.locale(actualLocale).format(this.defaultDateTimeFormat) : then.locale(actualLocale).fromNow(); + if ( diff > 7) { + const datePipe: DatePipe = new DatePipe(actualLocale); + return datePipe.transform(value, this.defaultDateTimeFormat); + } else { + return then.locale(actualLocale).fromNow(); + } } return ''; }