How to use the date-fns.startOfDay 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 jkuri / ng-daterangepicker / src / ng-daterangepicker / ng-daterangepicker.component.ts View on Github external
ngOnInit() {
    this.opened = false;
    this.date = dateFns.startOfDay(new Date());
    this.options = this.options || { theme: 'default', range: 'tm' };
    this.initNames();
    this.selectRange(this.options.range);
  }
github bullhorn / novo-elements / projects / novo-elements / src / elements / simple-table / cell-header.ts View on Github external
public filterData(filter?: any): void {
    let actualFilter = filter;
    if (this.config.filterConfig.type === 'date' && filter) {
      this.activeDateFilter = filter.label || this.labels.customDateRange;
      if (filter.startDate && filter.endDate) {
        actualFilter = {
          min: dateFns.startOfDay(filter.startDate.date),
          max: dateFns.startOfDay(dateFns.addDays(dateFns.startOfDay(filter.endDate.date), 1)),
        };
      } else {
        actualFilter = {
          min: filter.min ? dateFns.addDays(dateFns.startOfToday(), filter.min) : dateFns.startOfToday(),
          max: filter.max ? dateFns.addDays(dateFns.startOfTomorrow(), filter.max) : dateFns.startOfTomorrow(),
        };
      }
    }

    if (actualFilter && actualFilter.hasOwnProperty('value')) {
      actualFilter = filter.value;
    }

    if (this.changeTimeout) {
      clearTimeout(this.changeTimeout);
    }
github adarshpastakia / aurelia-ui-framework / dist / native-modules / ui-calendar.js View on Github external
var isBeforeMin = function (month, minDate, n) {
    if (n === void 0) { n = 0; }
    return isValid(minDate) ? isBefore(addMonths(startOfDay(month), n), startOfDay(minDate)) : false;
};
var isAfterMax = function (month, maxDate, n) {
github adarshpastakia / aurelia-ui-framework / src / calendar / calendar-utils.ts View on Github external
export const isDisabled = (config: IDateConfig, date: Date): boolean => {
  let min = config.minDate;
  let max = config.maxDate;

  if (config.page === CALENDAR_VIEWS.DAYS) {
    min = startOfDay(min);
    max = startOfDay(max);
  }
  if (config.page === CALENDAR_VIEWS.MONTHS) {
    min = startOfMonth(startOfDay(min));
    max = endOfMonth(startOfDay(max));
  }
  if (config.page === CALENDAR_VIEWS.YEARS) {
    min = startOfYear(startOfDay(min));
    max = startOfYear(startOfDay(max));
  }
  if (isBefore(date, min)) {
    return true;
  }
  if (isAfter(date, max)) {
    return true;
  }
  if (config.page === CALENDAR_VIEWS.DAYS && config.disabled) {
    const { disabled } = config;
    if (isArray(disabled)) {
      return disabled.includes(startOfDay(date).toISOString());
github adarshpastakia / aurelia-ui-framework / dist / es2015 / ui-calendar.js View on Github external
const isDisabled = (config, date) => {
    let min = config.minDate;
    let max = config.maxDate;
    if (config.page === CALENDAR_VIEWS.DAYS) {
        min = startOfDay(min);
        max = startOfDay(max);
    }
    if (config.page === CALENDAR_VIEWS.MONTHS) {
        min = startOfMonth(startOfDay(min));
        max = endOfMonth(startOfDay(max));
    }
    if (config.page === CALENDAR_VIEWS.YEARS) {
        min = startOfYear(startOfDay(min));
        max = startOfYear(startOfDay(max));
    }
    if (isBefore(date, min)) {
        return true;
    }
    if (isAfter(date, max)) {
        return true;
    }
github adarshpastakia / aurelia-ui-framework / dist / native-modules / ui-calendar.js View on Github external
max = endOfMonth(startOfDay(max));
    }
    if (config.page === CALENDAR_VIEWS.YEARS) {
        min = startOfYear(startOfDay(min));
        max = startOfYear(startOfDay(max));
    }
    if (isBefore(date, min)) {
        return true;
    }
    if (isAfter(date, max)) {
        return true;
    }
    if (config.page === CALENDAR_VIEWS.DAYS && config.disabled) {
        var disabled = config.disabled;
        if (isArray(disabled)) {
            return disabled.includes(startOfDay(date).toISOString());
        }
        else if (isFunction(disabled)) {
            return disabled({ date: date });
        }
    }
    return false;
};
github giuem / uptimerobot-page / src / services / uptimerobot.js View on Github external
function lastDays(distance) {
  const now = startOfDay(new Date());
  const dates = [];
  const ranges = [];
  const getTime = date => Math.floor(date.getTime() / 1000);
  for (let i = -distance; i < 0; i++) {
    const day0 = addDays(now, i);
    const day1 = addSeconds(addDays(day0, 1), -1);
    dates.push(format(day0, "MMM Do, YYYY"));
    ranges.push(`${getTime(day0)}_${getTime(day1)}`);
  }
  return { dates, ranges: ranges.join("-") };
}
github bullhorn / novo-elements / src / platform / utils / calendar-utils / CalendarUtils.ts View on Github external
function getWeekDay({ date }: { date: Date }): WeekDay {
  const today: Date = dateFns.startOfDay(new Date());
  return {
    date,
    isPast: date < today,
    isToday: dateFns.isSameDay(date, today),
    isFuture: date > today,
    isWeekend: WEEKEND_DAY_NUMBERS.indexOf(dateFns.getDay(date)) > -1,
  };
}
github bullhorn / novo-elements / src / platform / utils / calendar-utils / CalendarUtils.ts View on Github external
export function getDayView({ events = [], viewDate, hourSegments, dayStart, dayEnd, eventWidth, segmentHeight }: GetDayViewArgs): DayView {
  if (!events) {
    events = [];
  }

  const startOfView: Date = dateFns.setMinutes(dateFns.setHours(dateFns.startOfDay(viewDate), dayStart.hour), dayStart.minute);
  const endOfView: Date = dateFns.setMinutes(
    dateFns.setHours(dateFns.startOfMinute(dateFns.endOfDay(viewDate)), dayEnd.hour),
    dayEnd.minute,
  );
  const previousDayEvents: DayViewEvent[] = [];

  const dayViewEvents: DayViewEvent[] = getEventsInTimeRange(
    getEventsInPeriod({
      events: events.filter((event: CalendarEvent) => !event.allDay),
      periodStart: startOfView,
      periodEnd: endOfView,
    }),
    dayStart,
    dayEnd,
  )
    .sort((eventA: CalendarEvent, eventB: CalendarEvent) => {