Consolidate date adapter

This commit is contained in:
Michael Shamoon
2022-05-16 00:29:49 -07:00
parent 554eb32b33
commit e664cd249b
3 changed files with 16 additions and 38 deletions

View File

@@ -5,11 +5,20 @@ import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'
export class ISODateAdapter extends NgbDateAdapter<string> {
fromModel(value: string | null): NgbDateStruct | null {
if (value) {
let date = new Date(value)
return {
day: date.getDate(),
month: date.getMonth() + 1,
year: date.getFullYear(),
if (value.match(/\d\d\d\d\-\d\d\-\d\d/g)) {
const segs = value.split('-')
return {
year: parseInt(segs[0]),
month: parseInt(segs[1]),
day: parseInt(segs[2]),
}
} else {
let date = new Date(value)
return {
day: date.getDate(),
month: date.getMonth() + 1,
year: date.getFullYear(),
}
}
} else {
return null