function monthReducer(days, { data }) {
    const start = startOfDay(data.dateOfIssue)
    const end = endOfDay(data.validUntil)

    for (let day of eachDay(start, end)) {
        days.add(startOfDay(day).getTime())
    }

    return days
}
module.exports = function (schema, cb) {
  const now = Date.now()

  const doc = assign({}, schema, {
    updatedAt: startOfDay(now).getTime(),
    condition: getCondition(schema),
    link: getReferralLink(schema),
    timestamp: now
  })

  const schemaSerialized = serializer(doc)

  const tasks = [
    function validateSchema (next) {
      return validate(schemaSerialized, next)
    },
    function assignPrettyTitle (doc, next) {
      return titleize(doc, (err, title) =>
        next(err, assign({}, doc, { title }))
      )
    },
    function assignRangeProps (doc, next) {
      return next(null, assign(doc, getRangeProps(doc)))
    },
    function assignDescription (doc, next) {
      return next(null, assign(doc, { description: getDescription(doc) }))
    },
    function sanetizeProps (doc, next) {
      return next(null, pickBy(doc))
    }
  ]

  return waterfall(tasks, cb)
}
  parseSelectedDate(selectedDate) {
    if (selectedDate) {
      selectedDate = parse(selectedDate);

      // Selected Date should not be before min date or after max date
      if (isBefore(selectedDate, this._minDate)) {
        return this._minDate;
      } else if (isAfter(selectedDate, this._maxDate)) {
        return this._maxDate;
      }
    }

    return startOfDay(new Date(selectedDate));
  }
 disabledDays={day =>
     !days.has(startOfDay(day).getTime())
Example #5
0
export function getRelativeDate(timestamp, long = true) {
  const m = new Date(timestamp);
  const now = new Date();
  const age = differenceInMilliseconds(now, m);

  // Just now (when age < 45s)
  if (age < 45 * 1000) {
    return (long
      ? 'Just now'
      : false
    );
  }

  // 1-59 minutes ago (when 45s <= age < 59.5m)
  if (age < 59.5 * 60 * 1000) {
    const minutes = Math.round(age/60/1000);
    return (long
      ? pluralForm(minutes, 'minute') + ' ago'
      : pluralForm(minutes, 'min')
    );
  }

  // 1, 1.5, 2-8 hours ago (when 59.5m <= age < 8.5h)
  if (age < 8.5 * 3600 * 1000) {
    let hours = Math.round(age/1800/1000) / 2;
    if (hours > 2) {
      hours = Math.round(hours);
    }
    return (long
      ? pluralForm(hours, 'hour') + ' ago'
      : pluralForm(hours, 'hr')
    );
  }

  // Today at 15:37 (when age >= 8.5 hrs and it's today)
  if (m > startOfDay(now)) {
    return (long
      ? format(m, '[Today at] HH:mm')
      : format(m, 'HH:mm')
    );
  }

  // Yesterday at 15:37 (when age >= 8.5 hrs and it's yesterday)
  if (m > startOfDay(subDays(now, 1))) {
    return (long
      ? format(m, '[Yesterday at] HH:mm')
      : format(m, '[Yest] HH:mm')
    );
  }

  // Wed, 17 Feb (when yesterday < age < 14 days)
  if (m > subDays(now, 14)) {
    return (long
      ? format(m, 'ddd, D MMM')
      : format(m, 'D MMM')
    );
  }

  // 17 February (when age >= 14 days but it's still this year)
  if (m > startOfYear(now)) {
    return (long
      ? format(m, 'D MMMM')
      : format(m, 'D MMM')
    );
  }

  // 17 Feb 2016 (for everything else)
  return format(m, 'D MMM YYYY');
}