export function getClosestFutureDayToToday()

in packages/@fbcmobile-ui/Utils/DateUtils.js [62:92]


export function getClosestFutureDayToToday(
  dates: Array<moment$Moment>,
  jsLocale: string,
): ?moment$Moment {
  const todayMoment = moment()
    .locale(jsLocale)
    .startOf('day');

  const closestMoment = dates
    .map<moment$Moment>(date =>
      moment(date)
        .locale(jsLocale)
        .startOf('day'),
    )
    .filter(moment => moment.isSameOrAfter(todayMoment, 'days'))
    .reduce((closestMoment, currentMoment) => {
      if (closestMoment == null) {
        return currentMoment;
      }

      if (
        currentMoment.diff(todayMoment, 'days') <
        closestMoment.diff(todayMoment, 'days')
      ) {
        return currentMoment;
      }
      return closestMoment;
    }, null);

  return closestMoment;
}