created other branch for comments date
This commit is contained in:
parent
6654bd9e8a
commit
490266b7a2
@ -2,7 +2,10 @@
|
|||||||
<div class="comment-details-wrapper">
|
<div class="comment-details-wrapper">
|
||||||
<div class="comment-details">
|
<div class="comment-details">
|
||||||
<div>{{ getOwnerName(comment) }}</div>
|
<div>{{ getOwnerName(comment) }}</div>
|
||||||
<div>{{ comment.date | date: 'd MMM. yyyy, hh:mm a' }}</div>
|
<div [matTooltip]="comment.date | date: 'exactCommentDate'" [matTooltipPosition]="'above'">
|
||||||
|
<b> {{ getOwnerName(comment) }} </b>
|
||||||
|
{{ comment.date | date: 'commentDate' }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="comment-actions">
|
<div class="comment-actions">
|
||||||
<iqser-circle-button
|
<iqser-circle-button
|
||||||
|
|||||||
@ -5,6 +5,20 @@ import { DatePipe as BaseDatePipe } from '@angular/common';
|
|||||||
|
|
||||||
const HOURS_IN_A_DAY = 24;
|
const HOURS_IN_A_DAY = 24;
|
||||||
const MINUTES_IN_AN_HOUR = 60;
|
const MINUTES_IN_AN_HOUR = 60;
|
||||||
|
const MONTH_NAMES = {
|
||||||
|
0: 'jan',
|
||||||
|
1: 'feb',
|
||||||
|
2: 'mar',
|
||||||
|
3: 'apr',
|
||||||
|
4: 'may',
|
||||||
|
5: 'jun',
|
||||||
|
6: 'jul',
|
||||||
|
7: 'aug',
|
||||||
|
8: 'sep',
|
||||||
|
9: 'oct',
|
||||||
|
10: 'nov',
|
||||||
|
11: 'dec'
|
||||||
|
}
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'date'
|
name: 'date'
|
||||||
@ -18,6 +32,8 @@ export class DatePipe extends BaseDatePipe implements PipeTransform {
|
|||||||
transform(value: Date | string | number | null | undefined, format?: string, timezone?: string, locale?: string): string | null;
|
transform(value: Date | string | number | null | undefined, format?: string, timezone?: string, locale?: string): string | null;
|
||||||
transform(value: any, format?: string, timezone?: string, locale?: string): string {
|
transform(value: any, format?: string, timezone?: string, locale?: string): string {
|
||||||
if (format === 'timeFromNow') return this._getTimeFromNow(value);
|
if (format === 'timeFromNow') return this._getTimeFromNow(value);
|
||||||
|
if (format === 'commentDate') return this._getCommentDate(value);
|
||||||
|
if (format === 'exactCommentDate') return this._getExactCommentDate(value);
|
||||||
return super.transform(value, format, timezone, locale);
|
return super.transform(value, format, timezone, locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,4 +60,49 @@ export class DatePipe extends BaseDatePipe implements PipeTransform {
|
|||||||
|
|
||||||
return this._translateService.instant(`time.no-time-left`);
|
return this._translateService.instant(`time.no-time-left`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _getCommentDate(item: string) {
|
||||||
|
|
||||||
|
const date = moment(item);
|
||||||
|
const day = date.date();
|
||||||
|
const month = date.month();
|
||||||
|
const year = date.year();
|
||||||
|
|
||||||
|
const now = moment(Date.now());
|
||||||
|
const yesterday = now.clone().subtract(1, 'days').startOf('day');
|
||||||
|
const thisDay = now.date();
|
||||||
|
const thisMonth = now.month();
|
||||||
|
const thisYear = now.year();
|
||||||
|
|
||||||
|
const isTodayFormat = date.isSame(new Date(), 'day');
|
||||||
|
if (isTodayFormat) return moment(date, ['h:mm A']).format('HH:mm');
|
||||||
|
|
||||||
|
const isYesterdayFormat = date.isSame(yesterday, 'd');
|
||||||
|
if (isYesterdayFormat) return this._translateService.instant('yesterday');
|
||||||
|
|
||||||
|
const isShortMonthFormat = (day < thisDay - 1) && (year === thisYear || month >= thisMonth - 3)
|
||||||
|
if (isShortMonthFormat) {
|
||||||
|
const translatedMonth = this._translateService.instant(`months.${MONTH_NAMES[month]}`);
|
||||||
|
return `${day} ${translatedMonth}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isShortMonthYearFormat = (year === thisYear - 1) && (month < thisMonth - 3)
|
||||||
|
if (isShortMonthYearFormat) {
|
||||||
|
const translatedMonth = this._translateService.instant(`months.${MONTH_NAMES[month]}`);
|
||||||
|
return `${translatedMonth} ${year}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _getExactCommentDate(item: string) {
|
||||||
|
const date = moment(item);
|
||||||
|
const day = date.date();
|
||||||
|
const month = this._translateService.instant(`months.${MONTH_NAMES[date.month()]}`);
|
||||||
|
const year = date.year();
|
||||||
|
const hour = date.hour();
|
||||||
|
const minute = date.minute();
|
||||||
|
|
||||||
|
return this._translateService.instant('exact-comment-date', {day, month, year, hour, minute});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1238,6 +1238,22 @@
|
|||||||
"less-than-an-hour": "",
|
"less-than-an-hour": "",
|
||||||
"no-time-left": ""
|
"no-time-left": ""
|
||||||
},
|
},
|
||||||
|
"yesterday": "",
|
||||||
|
"exact-comment-date": "",
|
||||||
|
"months": {
|
||||||
|
"jan": "",
|
||||||
|
"feb": "",
|
||||||
|
"mar": "",
|
||||||
|
"apr": "",
|
||||||
|
"may": "",
|
||||||
|
"jun": "",
|
||||||
|
"jul": "",
|
||||||
|
"aug": "",
|
||||||
|
"sep": "",
|
||||||
|
"oct": "",
|
||||||
|
"nov": "",
|
||||||
|
"dec": ""
|
||||||
|
},
|
||||||
"top-bar": {
|
"top-bar": {
|
||||||
"navigation-items": {
|
"navigation-items": {
|
||||||
"back": "Zurück",
|
"back": "Zurück",
|
||||||
|
|||||||
@ -1250,6 +1250,22 @@
|
|||||||
"less-than-an-hour": "< 1 hour",
|
"less-than-an-hour": "< 1 hour",
|
||||||
"no-time-left": "Time to restore already passed"
|
"no-time-left": "Time to restore already passed"
|
||||||
},
|
},
|
||||||
|
"yesterday": "Yesterday",
|
||||||
|
"exact-comment-date": "{day} {month} {year} at {hour}:{minute}",
|
||||||
|
"months": {
|
||||||
|
"jan": "Jan.",
|
||||||
|
"feb": "Feb.",
|
||||||
|
"mar": "Mar.",
|
||||||
|
"apr": "Apr.",
|
||||||
|
"may": "May",
|
||||||
|
"jun": "Jun.",
|
||||||
|
"jul": "Jul.",
|
||||||
|
"aug": "Aug.",
|
||||||
|
"sep": "Sep.",
|
||||||
|
"oct": "Oct.",
|
||||||
|
"nov": "Nov.",
|
||||||
|
"dec": "Dec."
|
||||||
|
},
|
||||||
"top-bar": {
|
"top-bar": {
|
||||||
"navigation-items": {
|
"navigation-items": {
|
||||||
"back": "Back",
|
"back": "Back",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user