UI: Refactoring
This commit is contained in:
parent
031c7fe3ef
commit
2a80c0b38b
@ -17,21 +17,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NativeDatetimeAdapter } from '@mat-datetimepicker/core';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class CustomDateAdapter extends NativeDatetimeAdapter {
|
||||
|
||||
parse(value: string): Date {
|
||||
parse(value: string | number): Date {
|
||||
if (typeof value === 'number') {
|
||||
return new Date(value);
|
||||
}
|
||||
let newDate = null;
|
||||
let newDate = value;
|
||||
const formatToParts = Intl.DateTimeFormat(this.locale).formatToParts();
|
||||
if (formatToParts[0].type.toLowerCase() === 'day') {
|
||||
const literal = formatToParts[1].value;
|
||||
newDate = value.replace(new RegExp(`(\\d+[${literal}])(\\d+[${literal}])`), '$2$1');
|
||||
newDate = newDate.replace(new RegExp(`(\\d+[${literal}])(\\d+[${literal}])`), '$2$1');
|
||||
}
|
||||
return value ? new Date(Date.parse(newDate || value)) : null;
|
||||
return newDate ? new Date(Date.parse(newDate)) : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user