set the starting month as 0 instead of 1 ngb datepicker

614 Views Asked by At

I am using Datepicker control https://ng-bootstrap.github.io/#/components/datepicker/overview. I am using CustomDateParserFormatter to parse the date to different format. My issue is I am using dayjs to transform the dates which intern returns the date as the javascript object which means month will returned from 0 to 11, in that case datepicker shown november in the month dropdown if I enter 12/12/2012. Is there anywhere in the datepicker I can mention that the month starts from 0 and not 1 ? right now I am adding subtracting month which doesn't look clean.

current custom parser

  parse(value: string | null): NgbDateStruct | any {
    const dateFormat = 'MM/DD/YYYY';
    if (value) {
      const otherthing = dayjs(value).format(dateFormat);
      const tests = dayjs(otherthing);
      const something = {
        day: tests.date(),
        month: tests.month() + 1,
        year: tests.year(),
      };
      return something;
    }
    return null;
  }

  format(date: NgbDateStruct): string {
    if (date) {
      const something = dayjs(new Date(date.year, date.month - 1, date.day));
      return something.format('MM/DD/YYYY');
    }
    return '';
  }
0

There are 0 best solutions below