use created_date

This commit is contained in:
Michael Shamoon
2022-05-15 21:09:42 -07:00
parent 87866bcab0
commit caa9c49e05
9 changed files with 43 additions and 48 deletions

View File

@@ -1,5 +0,0 @@
// see https://github.com/dateutil/dateutil/issues/878 , JS Date does not
// seem to accept these strings as valid dates so we must normalize offset
export function normalizeDateStr(dateStr: string): string {
return dateStr.replace(/[\+-](\d\d):\d\d:\d\d/gm, `-$1:00`)
}

View File

@@ -5,11 +5,20 @@ import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'
export class ISODateTimeAdapter 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
@@ -17,8 +26,6 @@ export class ISODateTimeAdapter extends NgbDateAdapter<string> {
}
toModel(date: NgbDateStruct | null): string | null {
return date
? new Date(date.year, date.month - 1, date.day).toISOString()
: null
return date ? [date.year, date.month, date.day].join('-') : null
}
}