datepicker-adapter.ts 699B

12345678910111213141516171819202122
  1. /**
  2. * Angular bootstrap Date adapter
  3. */
  4. import { Injectable } from '@angular/core';
  5. import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
  6. import { Moment } from 'moment';
  7. import * as moment from 'moment';
  8. @Injectable()
  9. export class NgbDateMomentAdapter extends NgbDateAdapter<Moment> {
  10. fromModel(date: Moment): NgbDateStruct {
  11. if (date != null && moment.isMoment(date) && date.isValid()) {
  12. return { year: date.year(), month: date.month() + 1, day: date.date() };
  13. }
  14. return null;
  15. }
  16. toModel(date: NgbDateStruct): Moment {
  17. return date ? moment(date.year + '-' + date.month + '-' + date.day, 'YYYY-MM-DD') : null;
  18. }
  19. }