Skip to content

Commit

Permalink
fix(module:date-picker): restrict the date when it overflows at the m…
Browse files Browse the repository at this point in the history
…onth panel

close NG-ZORRO#1899
  • Loading branch information
wilsoncook committed Jul 31, 2018
1 parent 8e7a6cb commit c9cf871
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions components/date-picker/lib/candy-date/candy-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as addMonths from 'date-fns/add_months';
import * as addYears from 'date-fns/add_years';
import * as endOfMonth from 'date-fns/end_of_month';
import * as setDay from 'date-fns/set_day';
import * as setMonth from 'date-fns/set_month';
// import * as setYear from 'date-fns/set_year';
import { firstDayOfWeek } from './util';

Expand Down Expand Up @@ -108,10 +109,12 @@ export class CandyDate {
}

// NOTE: month starts from 0
// NOTE: Don't use the native API for month manipulation as it not restrict the date when it overflows, eg. (new Date('2018-7-31')).setMonth(1) will be date of 2018-3-03 instead of 2018-2-28
setMonth(month: number): CandyDate {
const date = new Date(this.nativeDate);
date.setMonth(month);
return new CandyDate(date);
// const date = new Date(this.nativeDate);
// date.setMonth(month);
// return new CandyDate(date);
return new CandyDate(setMonth(this.nativeDate, month));
}

addMonths(amount: number): CandyDate {
Expand Down

0 comments on commit c9cf871

Please sign in to comment.