Ng-zorro-antd: Internationalization - first day of the week (Sunday or Monday)

Created on 17 Oct 2018  ·  8Comments  ·  Source: NG-ZORRO/ng-zorro-antd

What problem does this feature solve?

By default, order of days in calendar is: Sunday, Monday etc. According to international standard ISO 8601, Monday is the first day of the week.

What does the proposed API look like?

There should be optional parameter for calendar (boolean, default: false). Setting this parameter to true allow change first day for week from Sunday to Monday (Sunday will be last day of week)

Calendar DatePicker

Most helpful comment

@vthinkxie Problem in: https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/calendar/nz-calendar.component.ts

private get calendarStart(): Date {
    return startOfWeek(startOfMonth(this.activeDate));
  }

and

private setUpDaysInWeek(): void {
    this.daysInWeek = [];
    const weekStart = startOfWeek(this.activeDate);
    for (let i = 0; i < 7; i++) {
      const date = addDays(weekStart, i);
      const title = this.i18n.formatDate(date, 'E');
      const label = this.i18n.formatDate(date, 'EEEEEE');
      this.daysInWeek.push({title, label});
    }
  }

In https://date-fns.org/v1.28.0/docs/startOfWeek function have option
startOfWeek(new Date(2014, 8, 2, 11, 55, 0), {weekStartsOn: 1})

All 8 comments

Some progress?

@wilsoncook Please write something)

@vthinkxie This problem in calendar too

@vthinkxie Problem in: https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/components/calendar/nz-calendar.component.ts

private get calendarStart(): Date {
    return startOfWeek(startOfMonth(this.activeDate));
  }

and

private setUpDaysInWeek(): void {
    this.daysInWeek = [];
    const weekStart = startOfWeek(this.activeDate);
    for (let i = 0; i < 7; i++) {
      const date = addDays(weekStart, i);
      const title = this.i18n.formatDate(date, 'E');
      const label = this.i18n.formatDate(date, 'EEEEEE');
      this.daysInWeek.push({title, label});
    }
  }

In https://date-fns.org/v1.28.0/docs/startOfWeek function have option
startOfWeek(new Date(2014, 8, 2, 11, 55, 0), {weekStartsOn: 1})

@vthinkxie, @wilsoncook Please, answer something about this issue.

refer to #2073

@Gromov-Roman You may use the temporary solution like @cosmodesantnik said:

import { CandyDate } from 'ng-zorro-antd';
CandyDate.prototype.firstDayOfWeek = () => 1;

@wilsoncook It don't work for calendar! Please see https://github.com/NG-ZORRO/ng-zorro-antd/issues/2293#issuecomment-434619754. This issue isn't about datepicker!

Was this page helpful?
0 / 5 - 0 ratings