How to use the date-fns.subDays 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 veritone / veritone-sdk / packages / veritone-react-common / src / components / Scheduler / index.js View on Github external
@withProps(props => {
  const scheduleType = getDefaultScheduleType(props);

  return {
    // Handle empty array passed to supportedScheduleTypes
    supportedScheduleTypes:
      get(props.supportedScheduleTypes, 'length') === 0
        ? ['Any']
        : props.supportedScheduleTypes,
    initialValues: {
      // This provides defaults to the form. Shallow merged with
      // props.initialValues to allow overriding.
      scheduleType,
      start: get(props, 'initialValues.start')
        ? new Date(props.initialValues.start)
        : subDays(initDate, 3),
      end: get(props, 'initialValues.end')
        ? new Date(props.initialValues.end)
        : initDate,
      repeatEvery: {
        number: '1',
        period: 'day'
      },
      daily: [
        {
          start: '00:00',
          end: '01:00'
        }
      ],
      weekly: {
        // make sure we set a default start/end for any days which aren't given
        // explicit default values in props.initialValues.weekly
github bleenco / abstruse / tests / unit / 050_new-server-api-routes.spec.ts View on Github external
it(`get job-runs should return data`, () => {
      const dateFrom = subDays(new Date(), 7);
      const dateTo = new Date();

      return sendGetRequest({}, `api/stats/job-runs/${dateFrom}/${dateTo}`).then(res => {
        expect(res).haveOwnProperty('data');
      });
    });
  });
github mattlewis92 / angular-calendar / demo / demo.component.ts View on Github external
viewDate: Date = new Date();

  actions: CalendarEventAction[] = [{
    label: '<i class="fa fa-fw fa-pencil"></i>',
    onClick: ({event}: {event: CalendarEvent}): void =&gt; {
      console.log('Edit event', event);
    }
  }, {
    label: '<i class="fa fa-fw fa-times"></i>',
    onClick: ({event}: {event: CalendarEvent}): void =&gt; {
      this.events = this.events.filter(iEvent =&gt; iEvent !== event);
    }
  }];

  events: CalendarEvent[] = [{
    start: subDays(startOfDay(new Date()), 1),
    end: addDays(new Date(), 1),
    title: 'A 3 day event',
    color: colors.red,
    actions: this.actions
  }, {
    start: startOfDay(new Date()),
    title: 'An event with no end date',
    color: colors.yellow,
    actions: this.actions,
    allDay: true
  }, {
    start: subDays(endOfMonth(new Date()), 3),
    end: addDays(endOfMonth(new Date()), 3),
    title: 'A long event that spans 2 months',
    color: colors.blue
  }];
github bullhorn / novo-elements / projects / novo-examples / src / components / data-table / data-table-remote / data-table-remote-example.ts View on Github external
constructor(private ref: ChangeDetectorRef, private modalService: NovoModalService) {
    for (let i = 0; i &lt; 1000; i++) {
      let day = i &lt; 500 ? dateFns.subDays(new Date(), i) : dateFns.addDays(new Date(), i - 500);
      this.staticDataSet1.push({
        id: i,
        embeddedObj: { id: i, test: `HMM ${i}`, another: { id: 777 } },
        simpleEmbeddedObj: { id: i },
        name: `(1) Name ${i}`,
        status: `(1) Status ${i}`,
        priority: this.getPriority(),
        enabled: i % 2 === 0,
        date: day,
        dateTime: day,
        time: day,
        money: i + 10,
        percent: i / 100,
        telephone: '555-555-5555',
        email: 'test@google.com',
        address: { city: 'City', state: null },
github sourcegraph / sourcegraph / dev / release / src / release.ts View on Github external
const events: EventOptions[] = [
                {
                    title: 'Release captain: prepare for branch cut (5 working days until release)',
                    description: 'See the release tracking issue for TODOs',
                    startDateTime: new Date(c.fiveWorkingDaysBeforeRelease).toISOString(),
                    endDateTime: addMinutes(new Date(c.fiveWorkingDaysBeforeRelease), 1).toISOString(),
                },
                {
                    title: 'Release captain: branch cut (4 working days until release)',
                    description: 'See the release tracking issue for TODOs',
                    startDateTime: new Date(c.fourWorkingDaysBeforeRelease).toISOString(),
                    endDateTime: addMinutes(new Date(c.fourWorkingDaysBeforeRelease), 1).toISOString(),
                },
                ...eachDayOfInterval({
                    start: addDays(new Date(c.fourWorkingDaysBeforeRelease), 1),
                    end: subDays(new Date(c.oneWorkingDayBeforeRelease), 1),
                })
                    .filter(d => !isWeekend(d))
                    .map(d => ({
                        title: 'Release captain: cut new release candidate',
                        description: 'See release tracking issue for TODOs',
                        startDateTime: d.toISOString(),
                        endDateTime: addMinutes(d, 1).toISOString(),
                    })),
                {
                    title: 'Release captain: tag final release (1 working day before release)',
                    description: 'See the release tracking issue for TODOs',
                    startDateTime: new Date(c.oneWorkingDayBeforeRelease).toISOString(),
                    endDateTime: addMinutes(new Date(c.oneWorkingDayBeforeRelease), 1).toISOString(),
                },
                {
                    title: `Cut release branch ${c.majorVersion}.${c.minorVersion}`,
github FaiChou / react-native-slideable-calendar-strip / lib / CalendarStrip.js View on Github external
loadPreviousTwoWeek(originalDates) {
    const originalFirstDate = originalDates[0];
    const originalLastDate = originalDates[originalDates.length-1];
    const firstDayOfPrevious2Week = subDays(originalFirstDate, 7 * 2);
    const eachDays = eachDay(firstDayOfPrevious2Week, originalLastDate);
    this.setState(prevState => ({
      datas: eachDays,
      currentPage: prevState.currentPage+2,
      pageOfToday: prevState.pageOfToday+2,
    }), () => {
      this.scrollToPage(2, false);
    });
  }
github xmlking / ngx-starter-kit / libs / widgets / src / lib / demo-data / inbox-demo-data.ts View on Github external
attachments: ['assets/img/attachments/2.jpg', 'assets/img/attachments/2.jpg', 'assets/img/attachments/5.jpg'],
  },
  {
    id: '5aaa797af9d59b1b2e78f566',
    from: {
      name: 'Hines Chaney',
      mail: 'demo@demomail.com',
    },
    to: {
      name: 'David Smith',
      mail: 'davidsmith@demomail.com',
    },
    subject: 'Pariatur reprehenderit labore consectetur id laboris ipsum Lorem commodo ea minim mollit magna mollit.',
    content:
      'Nulla irure ea voluptate ut laborum dolore proident esse qui eu. Anim dolore magna do velit laboris aliqua nostrud minim ipsum. Qui tempor do est et non amet nostrud anim cupidatat ex aliquip et nisi.',
    when: subDays(new Date(), 26),
    read: false,
    starred: false,
    labels: [],
    group: 'spam',
    attachments: [],
  },
  {
    id: '5aaa797a22bb3083a62fec12',
    from: {
      name: 'Paige Morris',
      mail: 'demo@demomail.com',
    },
    to: {
      name: 'David Smith',
      mail: 'davidsmith@demomail.com',
    },
github mattlewis92 / angular-calendar / demos / demo-modules / kitchen-sink / component.ts View on Github external
events: CalendarEvent[] = [
    {
      start: subDays(startOfDay(new Date()), 1),
      end: addDays(new Date(), 1),
      title: 'A 3 day event',
      color: colors.red,
      actions: this.actions
    },
    {
      start: startOfDay(new Date()),
      title: 'An event with no end date',
      color: colors.yellow,
      actions: this.actions
    },
    {
      start: subDays(endOfMonth(new Date()), 3),
      end: addDays(endOfMonth(new Date()), 3),
      title: 'A long event that spans 2 months',
      color: colors.blue
    },
    {
      start: addHours(startOfDay(new Date()), 2),
      end: new Date(),
      title: 'A draggable and resizable event',
      color: colors.yellow,
      actions: this.actions,
      resizable: {
        beforeStart: true,
        afterEnd: true
      },
      draggable: true
    }
github wpcfan / taskmgr / src / app / shared / components / age-input.ts View on Github external
private toDate(age: Age): string {
    const now = new Date();
    switch (age.unit) {
      case AgeUnit.Year: {
        return convertToDate(subYears(now, age.age));
      }
      case AgeUnit.Month: {
        return convertToDate(subMonths(now, age.age));
      }
      case AgeUnit.Day: {
        return convertToDate(subDays(now, age.age));
      }
      default: {
        return '1991-01-01';
      }
    }
  }
}
github mjackson / unpkg / modules / actions / serveStats.js View on Github external
export default function serveStats(req, res) {
  let since, until;
  if (req.query.period) {
    switch (req.query.period) {
      case 'last-day':
        until = startOfDay(new Date());
        since = subDays(until, 1);
        break;
      case 'last-week':
        until = startOfDay(new Date());
        since = subDays(until, 7);
        break;
      case 'last-month':
      default:
        until = startOfDay(new Date());
        since = subDays(until, 30);
    }
  } else {
    until = req.query.until
      ? new Date(req.query.until)
      : startOfDay(new Date());
    since = req.query.since ? new Date(req.query.since) : subDays(until, 1);
  }

  if (isNaN(since.getTime())) {
    return res.status(403).send({ error: '?since is not a valid date' });
  }

  if (isNaN(until.getTime())) {
    return res.status(403).send({ error: '?until is not a valid date' });
  }