FarmMapsLib/projects/common/src/fm/services/date-adapter.service.ts

17 lines
534 B
TypeScript
Raw Normal View History

2019-07-15 14:54:19 +00:00
import { Component, Injectable } from '@angular/core';
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
2019-11-05 16:19:33 +00:00
@Injectable({
providedIn: 'root',
})
2019-07-15 14:54:19 +00:00
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;
}
}