Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 26x 26x 26x 26x 20x 2x 18x 10x 8x 4x 4x 18x 26x 15x 14x | import { formatDate } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
export function formatISHDate(
value: string | number | Date,
format = 'mediumDate',
lang: string,
timezone?: string
): string {
if (!value || !lang) {
return 'undefined';
}
let date: Date;
if (typeof value === 'number') {
date = new Date(value);
} else if (typeof value === 'string') {
date = new Date(Date.parse(value));
} else {
date = value;
}
// if no time zone is given take the user's current time zone
return formatDate(date, format, lang, timezone);
}
/**
* The date pipe converts a number, string or date into a localized date format
* example values:
* as number: 1581690101334
* as string: '01 Jan 1970 00:00:00 GMT'
* other parameters see also angular date pipe
*/
@Pipe({ name: 'ishDate', pure: true })
export class DatePipe implements PipeTransform {
constructor(private translateService: TranslateService) {}
transform(value: string | number | Date, format = 'mediumDate', timezone?: string): string {
return formatISHDate(value, format, this.translateService.currentLang, timezone);
}
}
|