FarmMapsLib/projects/common/src/fm/services/date-adapter.service.ts
Willem Dantuma 9ebce8e0bb
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
Some refactoring
2019-11-05 17:19:33 +01:00

17 lines
534 B
TypeScript

import { Component, Injectable } from '@angular/core';
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
@Injectable({
providedIn: 'root',
})
export class NgbDateNativeAdapter extends NgbDateAdapter<Date> {
fromModel(date: Date): NgbDateStruct {
return (date && date.getFullYear) ? {year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate()} : null;
}
toModel(date: NgbDateStruct): Date {
return date ? new Date(Date.UTC(date.year, date.month - 1, date.day)) : null;
}
}