2019-10-25 13:16:11 +09:00
|
|
|
import { Pipe, PipeTransform } from '@angular/core';
|
|
|
|
import { StringUtil } from '../utils/string.util';
|
|
|
|
|
|
|
|
@Pipe({
|
2019-11-12 14:08:14 +09:00
|
|
|
name: 'dateToStringChatList',
|
2019-10-25 13:16:11 +09:00
|
|
|
})
|
|
|
|
export class DateToStringForChatRoomListPipe implements PipeTransform {
|
|
|
|
transform(value: any): string {
|
|
|
|
const curDate = new Date();
|
|
|
|
const yesterDate = new Date(curDate.getTime() - 1 * 24 * 60 * 60 * 1000);
|
|
|
|
let date: Date;
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
date = new Date(value.toString());
|
|
|
|
} else if (value instanceof Date) {
|
|
|
|
date = value;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
curDate.getFullYear() === date.getFullYear() &&
|
|
|
|
curDate.getMonth() === date.getMonth() &&
|
|
|
|
curDate.getDate() === date.getDate()
|
|
|
|
) {
|
|
|
|
// 당일
|
|
|
|
return StringUtil.dateFormat(date, 'a/p HH:mm');
|
|
|
|
} else if (
|
|
|
|
yesterDate.getFullYear() === date.getFullYear() &&
|
|
|
|
yesterDate.getMonth() === date.getMonth() &&
|
|
|
|
yesterDate.getDate() === date.getDate()
|
|
|
|
) {
|
|
|
|
// 어제
|
|
|
|
return '어제';
|
|
|
|
} else {
|
|
|
|
return StringUtil.dateFormat(date, 'MM.dd');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-12 14:08:14 +09:00
|
|
|
|
|
|
|
@Pipe({
|
|
|
|
name: 'dateToStringFormat',
|
|
|
|
})
|
|
|
|
export class DateToStringFormatPipe implements PipeTransform {
|
|
|
|
transform(value: any, format?: string): string {
|
|
|
|
const date = new Date(value.toString());
|
|
|
|
|
|
|
|
if (!!format) {
|
|
|
|
return StringUtil.dateFormat(date, format);
|
|
|
|
} else {
|
|
|
|
return StringUtil.dateFormat(date, 'YYYY.MM.DD');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|