mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Consolidate date adapter
This commit is contained in:
parent
94954eeba3
commit
d5e340d0f6
@ -61,7 +61,7 @@ import { SafeUrlPipe } from './pipes/safeurl.pipe'
|
|||||||
import { SafeHtmlPipe } from './pipes/safehtml.pipe'
|
import { SafeHtmlPipe } from './pipes/safehtml.pipe'
|
||||||
import { CustomDatePipe } from './pipes/custom-date.pipe'
|
import { CustomDatePipe } from './pipes/custom-date.pipe'
|
||||||
import { DateComponent } from './components/common/input/date/date.component'
|
import { DateComponent } from './components/common/input/date/date.component'
|
||||||
import { ISODateTimeAdapter } from './utils/ngb-iso-date-time-adapter'
|
import { ISODateAdapter } from './utils/ngb-iso-date-adapter'
|
||||||
import { LocalizedDateParserFormatter } from './utils/ngb-date-parser-formatter'
|
import { LocalizedDateParserFormatter } from './utils/ngb-date-parser-formatter'
|
||||||
import { ApiVersionInterceptor } from './interceptors/api-version.interceptor'
|
import { ApiVersionInterceptor } from './interceptors/api-version.interceptor'
|
||||||
import { ColorSliderModule } from 'ngx-color/slider'
|
import { ColorSliderModule } from 'ngx-color/slider'
|
||||||
@ -188,7 +188,7 @@ registerLocaleData(localeZh)
|
|||||||
},
|
},
|
||||||
FilterPipe,
|
FilterPipe,
|
||||||
DocumentTitlePipe,
|
DocumentTitlePipe,
|
||||||
{ provide: NgbDateAdapter, useClass: ISODateTimeAdapter },
|
{ provide: NgbDateAdapter, useClass: ISODateAdapter },
|
||||||
{ provide: NgbDateParserFormatter, useClass: LocalizedDateParserFormatter },
|
{ provide: NgbDateParserFormatter, useClass: LocalizedDateParserFormatter },
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent],
|
bootstrap: [AppComponent],
|
||||||
|
@ -5,12 +5,21 @@ import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'
|
|||||||
export class ISODateAdapter extends NgbDateAdapter<string> {
|
export class ISODateAdapter extends NgbDateAdapter<string> {
|
||||||
fromModel(value: string | null): NgbDateStruct | null {
|
fromModel(value: string | null): NgbDateStruct | null {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
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)
|
let date = new Date(value)
|
||||||
return {
|
return {
|
||||||
day: date.getDate(),
|
day: date.getDate(),
|
||||||
month: date.getMonth() + 1,
|
month: date.getMonth() + 1,
|
||||||
year: date.getFullYear(),
|
year: date.getFullYear(),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
import { Injectable } from '@angular/core'
|
|
||||||
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap'
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class ISODateTimeAdapter extends NgbDateAdapter<string> {
|
|
||||||
fromModel(value: string | null): NgbDateStruct | null {
|
|
||||||
if (value) {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
toModel(date: NgbDateStruct | null): string | null {
|
|
||||||
return date ? [date.year, date.month, date.day].join('-') : null
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user