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

15 lines
509 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';
@Injectable()
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;
}
}