import { NativeDateAdapter } from '@angular/material/core';
import dayjs from 'dayjs';
import customParseFormat from 'dayjs/plugin/customParseFormat';
import { Injectable } from '@angular/core';

dayjs.extend(customParseFormat);

@Injectable()
export class CustomDateAdapter extends NativeDateAdapter {
    parse(value: any, parseFormat: string): Date | null {
        return dayjs(value, parseFormat).toDate();
    }

    format(date: Date, displayFormat: string): string {
        return dayjs(date).format(displayFormat);
    }
}
