date-fns#differenceInCalendarDays JavaScript Examples

The following examples show how to use date-fns#differenceInCalendarDays. 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: relativeCommitTimeCalculator.js    From gitconvex with Apache License 2.0 6 votes vote down vote up
export function relativeCommitTimeCalculator(commitTime) {
  let commitRelativeTime;

  const days = differenceInCalendarDays(new Date(), new Date(commitTime));
  const hours = differenceInHours(new Date(), new Date(commitTime));
  const minutes = differenceInMinutes(new Date(), new Date(commitTime));

  if (days > 0) {
    if (days >= 30) {
      const month = differenceInMonths(new Date(), new Date(commitTime));
      commitRelativeTime =
        month === 1 ? month + " Month Ago" : month + " Months Ago";
    } else if (days >= 365) {
      const year = differenceInYears(new Date(), new Date(commitTime));
      commitRelativeTime =
        year === 1 ? year + " Year Ago" : year + " Years Ago";
    } else {
      commitRelativeTime = days === 1 ? days + " Day Ago" : days + " Days Ago";
    }
  } else if (hours > 0) {
    commitRelativeTime =
      hours === 1 ? hours + " Hour Ago" : hours + " Hours Ago";
  } else if (minutes > 0) {
    commitRelativeTime =
      minutes === 1 ? minutes + " Minute Ago" : minutes + " Minutes Ago";
  } else {
    commitRelativeTime = "recent commit";
  }

  return commitRelativeTime;
}
Example #2
Source File: date.js    From umami with MIT License 6 votes vote down vote up
export function getDateRangeValues(startDate, endDate) {
  let unit = 'year';
  if (differenceInHours(endDate, startDate) <= 48) {
    unit = 'hour';
  } else if (differenceInCalendarDays(endDate, startDate) <= 90) {
    unit = 'day';
  } else if (differenceInCalendarMonths(endDate, startDate) <= 24) {
    unit = 'month';
  }

  return { startDate: startOfDay(startDate), endDate: endOfDay(endDate), unit };
}
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],
}