How to use the date-fns.startOfWeek function in date-fns

To help you get started, we’ve selected a few date-fns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bullhorn / novo-elements / projects / novo-elements / src / elements / date-picker / DatePicker.ts View on Github external
select(event: Event, day: Day, fireEvents: boolean) {
    Helpers.swallowEvent(event);
    if (this.range) {
      if (this.weekRangeSelect) {
        this.selected = dateFns.startOfWeek(day.date, { weekStartsOn: this.weekStart });
        this.selected2 = dateFns.endOfWeek(day.date, { weekStartsOn: this.weekStart });
        this.selectedLabel = this.labels.formatDateWithFormat(this.selected, {
          month: 'short',
          day: '2-digit',
          year: 'numeric',
        });
        this.selected2Label = this.labels.formatDateWithFormat(this.selected2, {
          month: 'short',
          day: '2-digit',
          year: 'numeric',
        });
        // Make sure to fire this, since we default to the current week selected!
        if (!fireEvents && this.weekRangeSelect) {
          this.fireRangeSelect();
        }
      } else if (this.rangeSelectMode === 'startDate') {
github bullhorn / novo-elements / src / elements / date-picker / DatePicker.ts View on Github external
buildMonth(start: Date, month: Date) {
        // Reset the weeks
        this.weeks = [];

        // House keeping variables to know when we are done building the month
        let done = false,
            date = dateFns.startOfWeek(start, { weekStartsOn: this.weekStart }),
            monthIndex = date.getMonth(),
            count = 0;

        while (!done) {
            // Build the days for the weeks
            this.weeks.push({ days: this.buildWeek(new Date(date.getTime()), month) });

            // Increment variables for the next iteration
            date = dateFns.addDays(date, 7);
            done = count++ > 2 && monthIndex !== date.getMonth();
            monthIndex = date.getMonth();
        }
    }
github synyx / urlaubsverwaltung / src / main / webapp / components / datepicker / webcomponentDatepicker.js View on Github external
render({ date, selected }) {
    const currentMonth = getMonth(date);
    const firstOfMonth = startOfMonth(date);
    const firstOfWeek = startOfWeek(firstOfMonth);

    this.thead.innerHTML = `
      
        ${times(7).map(daysToAdd => `${format(addDays(firstOfWeek, daysToAdd), 'dd')}`).join('')}
      
    `;

    this.tbody.innerHTML = `
      
        ${times(7).map(daysToAdd => this.renderDay({ currentMonth, selected, date: addDays(firstOfWeek, daysToAdd) })).join('')}
      
      
        ${times(7).map(daysToAdd => this.renderDay({ currentMonth, selected, date: addWeeks(addDays(firstOfWeek, daysToAdd), 1) })).join('')}
      
      
        ${times(7).map(daysToAdd => this.renderDay({ currentMonth, selected, date: addWeeks(addDays(firstOfWeek, daysToAdd), 2) })).join('')}
github SCHKN / techoverdose / client / src / components / filtering / filterUtils.js View on Github external
export const getLowerBound = filter => {
  const currentDate = new Date();
  switch (filter) {
    case "day":
      return format(currentDate, "YYYY-MM-DD");
    case "week":
      return format(startOfWeek(currentDate), "YYYY-MM-DD");
    case "month":
      return format(startOfMonth(currentDate), "YYYY-MM-DD");
    case "year":
      return format(startOfYear(currentDate), "YYYY-MM-DD");
    default:
      return format(currentDate, "YYYY-MM-DD");
  }
};
github ui-model / ui-model / projects / ui-model / common / src / lib / calendar / calendar.ts View on Github external
update(): void {
    const firstDayOfMonth = startOfMonth(this.fakeValue);
    const firstWeek = getISOWeek(firstDayOfMonth);
    const firstSunday = startOfWeek(firstDayOfMonth);

    this._weeks = range(firstWeek, firstWeek + 6);
    this._dates = this.weeks.map((week) => {
      return range(0, 7).map((day) => {
        return addDays(addWeeks(firstSunday, week - firstWeek), day);
      });
    });
    this._nearlyYears = range(this.year - 5, this.year + 6);
  }
github ui-model / ui-model / projects / ui-model / common / src / lib / calendar / calendar.ts View on Github external
function weekdaysMin(): string[] {
  const now = new Date();
  return eachDay(startOfWeek(now), endOfWeek(now))
    .map((day) => format(day, 'dd'));
}
github WeTrustPlatform / paramount / src / components / Calendars / Month / WeekDays.tsx View on Github external
const getDaysInWeek = (firstDayOfWeekIndex: number) => {
  const week = [];
  const firstDayOfWeek = addDays(startOfWeek(new Date()), firstDayOfWeekIndex);

  for (let index = 0; index < 7; index++) {
    week.push(addDays(firstDayOfWeek, index));
  }

  return week;
};
github adarshpastakia / aurelia-ui-framework / dist / native-modules / ui-calendar.js View on Github external
DaysPage.prototype.monthChanged = function (newMonth) {
        this.month = newMonth || new Date();
        var start = startOfMonth(this.month);
        this.pageStart = startOfWeek(startOfMonth(this.month));
        if (getDay(start) < 3) {
            this.pageStart = addWeeks(this.pageStart, -1);
        }
    };
    DaysPage.prototype.weekTitle = function (week) {
github gpbl / react-day-picker / package / lib / index.esm.js View on Github external
function getOutsideStartDays(day, props) {
    var locale = props.locale;
    var days = [];
    var firstDayOfWeek = startOfWeek(day.date, { locale: locale });
    var startDiff = differenceInDays(day.date, firstDayOfWeek);
    for (var i = 0; i < startDiff; i++) {
        var day_1 = addDays(firstDayOfWeek, i);
        var hidden = props.fromMonth && day_1 < props.fromMonth;
        var modifiers = { outside: 'start', hidden: hidden };
        var dateWithModifiers = new DateWithModifiers(day_1, modifiers, props);
        days.push(dateWithModifiers);
    }
    return days;
}