mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-11 10:00:48 -05:00
28 lines
728 B
TypeScript
28 lines
728 B
TypeScript
import { Injectable } from "@angular/core";
|
|
import { NgbDateAdapter, NgbDateStruct } from "@ng-bootstrap/ng-bootstrap";
|
|
|
|
@Injectable()
|
|
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()
|
|
}
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
|
|
toModel(date: NgbDateStruct | null): string | null {
|
|
if (date) {
|
|
return date.year.toString().padStart(4, '0') + "-" + date.month.toString().padStart(2, '0') + "-" + date.day.toString().padStart(2, '0')
|
|
} else {
|
|
return null
|
|
}
|
|
}
|
|
}
|