date-fns#addHours JavaScript Examples

The following examples show how to use date-fns#addHours. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: item.js    From Hack-the-October2020 with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Calculate the time it will take to respawn this tile
   *
   * @param {string} respawnTime Time in short notation (eg: '1hr 4m 18s')
   * @returns {integer}
   */
  static calculateRespawnTime(respawnTime) {
    // MOVE TO OBJECT ENGINE CLASS AND EXTEND FROM HERE?
    const pickedUpAt = new Date();
    const respawnsIn = respawnTime;

    const add = {
      hours: Item.parseTime(respawnsIn, 'h'),
      minutes: Item.parseTime(respawnsIn, 'm'),
      seconds: Item.parseTime(respawnsIn, 's'),
    };

    let timeToAdd = 0;
    if (typeof (add.hours) === 'number') timeToAdd = addHours(pickedUpAt, add.hours);
    if (typeof (add.minutes) === 'number') timeToAdd = addMinutes(pickedUpAt, add.minutes);
    if (typeof (add.seconds) === 'number') timeToAdd = addSeconds(pickedUpAt, add.seconds);

    return timeToAdd;
  }
Example #2
Source File: index.js    From react-timeline-range-slider with MIT License 6 votes vote down vote up
TimeRange.defaultProps = {
  selectedInterval: [
    set(new Date(), { minutes: 0, seconds: 0, milliseconds: 0 }),
    set(addHours(new Date(), 1), { minutes: 0, seconds: 0, milliseconds: 0 })
  ],
  timelineInterval: [startOfToday(), endOfToday()],
  formatTick: ms => format(new Date(ms), 'HH:mm'),
  disabledIntervals: [],
  step: 1000*60*30,
  ticksNumber: 48,
  error: false,
  mode: 3,
}
Example #3
Source File: date.js    From umami with MIT License 5 votes vote down vote up
dateFuncs = {
  minute: [differenceInMinutes, addMinutes, startOfMinute],
  hour: [differenceInHours, addHours, startOfHour],
  day: [differenceInCalendarDays, addDays, startOfDay],
  month: [differenceInCalendarMonths, addMonths, startOfMonth],
  year: [differenceInCalendarYears, addYears, startOfYear],
}
Example #4
Source File: index.js    From neutron with Mozilla Public License 2.0 4 votes vote down vote up
DialogPauseNotifications = () => {
  // const classes = useStyles();
  const dispatch = useDispatch();

  const pauseNotificationsInfo = useSelector((state) => state.notifications.pauseNotificationsInfo);
  const showDateTimePicker = useSelector((state) => state.notifications.showDateTimePicker);

  const shouldPauseNotifications = pauseNotificationsInfo !== null;

  const quickShortcuts = [
    {
      name: '15 minutes',
      calcDate: () => addMinutes(new Date(), 15),
    },
    {
      name: '30 minutes',
      calcDate: () => addMinutes(new Date(), 30),
    },
    {
      name: '45 minutes',
      calcDate: () => addMinutes(new Date(), 45),
    },
    {
      name: '1 hour',
      calcDate: () => addHours(new Date(), 1),
    },
    {
      name: '2 hours',
      calcDate: () => addHours(new Date(), 2),
    },
    {
      name: '4 hours',
      calcDate: () => addHours(new Date(), 4),
    },
    {
      name: '6 hours',
      calcDate: () => addHours(new Date(), 6),
    },
    {
      name: '8 hours',
      calcDate: () => addHours(new Date(), 8),
    },
    {
      name: '10 hours',
      calcDate: () => addHours(new Date(), 8),
    },
    {
      name: '12 hours',
      calcDate: () => addHours(new Date(), 12),
    },
    {
      name: 'Until tomorrow',
      calcDate: () => addDays(new Date(), 1),
    },
    {
      name: 'Until next week',
      calcDate: () => addWeeks(new Date(), 1),
    },
  ];

  const pauseNotif = (tilDate) => {
    requestSetPreference('pauseNotifications', `pause:${tilDate.toString()}`);
    requestShowNotification({
      title: 'Notifications paused',
      body: `Notifications paused until ${formatDate(tilDate)}.`,
    });
    getCurrentWindow().close();
  };

  const renderList = () => {
    if (shouldPauseNotifications) {
      return (
        <List
          dense
          disablePadding
        >
          <ListItem sx={{
            background: `url(${nightBackgroundPng})`,
            height: 210,
            backgroundSize: 400,
            alignItems: 'flex-end',
          }}
          >
            <ListItemText
              primary={`Notifications paused until
              ${formatDate(new Date(pauseNotificationsInfo.tilDate))}.`}
              sx={{
                color: 'common.white',
              }}
            />
          </ListItem>
          <ListItem button>
            <ListItemText
              primary="Resume notifications"
              onClick={() => {
                if (pauseNotificationsInfo.reason === 'scheduled') {
                  requestSetPreference('pauseNotifications', `resume:${pauseNotificationsInfo.tilDate}`);
                } else if (pauseNotificationsInfo.schedule
                  && new Date() < new Date(pauseNotificationsInfo.schedule.to)) {
                  requestSetPreference('pauseNotifications', `resume:${pauseNotificationsInfo.schedule.to}`);
                } else {
                  requestSetPreference('pauseNotifications', null);
                }
                requestShowNotification({
                  title: 'Notifications resumed',
                  body: 'Notifications are now resumed.',
                });
                getCurrentWindow().close();
              }}
            />
          </ListItem>
          {pauseNotificationsInfo.reason !== 'scheduled' && (
            <>
              <Divider />
              <ListItem
                button
                onClick={() => {
                  const template = quickShortcuts.map((shortcut) => ({
                    label: shortcut.name,
                    click: () => pauseNotif(shortcut.calcDate()),
                  }));
                  template.push({
                    label: 'Custom',
                    click: () => dispatch(updateShowDateTimePicker(true)),
                  });
                  const menu = Menu.buildFromTemplate(template);
                  menu.popup({
                    window: getCurrentWindow(),
                  });
                }}
              >
                <ListItemText primary="Adjust time" />
                <ChevronRightIcon color="action" />
              </ListItem>
            </>
          )}
          <Divider />
          <ListItem button>
            <ListItemText
              primary={pauseNotificationsInfo.reason === 'scheduled' ? 'Adjust schedule...' : 'Pause notifications by schedule...'}
              onClick={() => {
                requestShowPreferencesWindow('notifications');
                getCurrentWindow().close();
              }}
            />
          </ListItem>
        </List>
      );
    }

    return (
      <List
        dense
        disablePadding
        subheader={<ListSubheader component="div">Pause notifications</ListSubheader>}
      >
        {quickShortcuts.map((shortcut) => (
          <ListItem
            button
            key={shortcut.name}
            onClick={() => pauseNotif(shortcut.calcDate())}
          >
            <ListItemText primary={shortcut.name} />
          </ListItem>
        ))}
        <ListItem
          button
          onClick={() => dispatch(updateShowDateTimePicker(true))}
        >
          <ListItemText primary="Custom..." />
        </ListItem>
        <Divider />
        <DateTimePicker
          value={new Date()}
          onChange={pauseNotif}
          label="Custom"
          open={showDateTimePicker}
          onOpen={() => dispatch(updateShowDateTimePicker(true))}
          onClose={() => dispatch(updateShowDateTimePicker(false))}
          disablePast
          showTodayButton
          // eslint-disable-next-line react/jsx-props-no-spreading
          renderInput={() => (
            <ListItem button>
              <ListItemText
                primary="Pause notifications by schedule..."
                onClick={() => {
                  requestShowPreferencesWindow('notifications');
                  getCurrentWindow().close();
                }}
              />
            </ListItem>
          )}
        />
      </List>
    );
  };

  return (
    <>
      {renderList()}
    </>
  );
}