A simple, universal public Statuspage. https://status.sp-codes.de
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.2 KiB

import { Pipe, PipeTransform } from '@angular/core';
import * as dayjs from 'dayjs';
import * as utc from 'dayjs/plugin/utc';
import * as relativeTime from 'dayjs/plugin/relativeTime';
import * as localizedFormat from 'dayjs/plugin/localizedFormat';
import {TranslateService} from '@ngx-translate/core';
import 'dayjs/locale/de';
dayjs.extend(utc);
dayjs.extend(relativeTime);
dayjs.extend(localizedFormat);
@Pipe({
name: 'dayjs',
pure: false
})
export class DayjsPipe implements PipeTransform {
constructor(private translate: TranslateService) {
}
transform(value: string | Date, method: string, ...args: any[]): string {
const date = dayjs.utc(value);
switch (method) {
case 'to':
const to = args[0] ? dayjs.utc(args[0]) : dayjs.utc();
const suffix = args.length > 1 && args[1] === true;
return date.locale(this.translate.currentLang).to(to, !suffix);
case 'from':
const from = args[0] ? dayjs.utc(args[0]) : dayjs.utc();
return date.locale(this.translate.currentLang).from(from);
case 'format':
return date.local().locale(this.translate.currentLang).format(args[0]);
}
throw new Error('please pass a method to use!');
}
}