/** Create a filter for the entities based on the specifications of the tab. */
  public static UnaryFunctor<Individual, Boolean> getTimeFilter(final Tab tab, final DateTime now) {
    UnaryFunctor<Individual, Boolean> out = null;

    if (tab.getDayLimit() == 0) {
      out = VitroFilterUtils.getSunsetWindowFilter(now.toDate()).getIndividualFilter();

    } else if (tab.getDayLimit() > 0) {
      out =
          new UnaryFunctor<Individual, Boolean>() {
            public Boolean fn(Individual arg) {
              if (arg.getTimekey() == null) return Boolean.FALSE;

              DateTime timekey = new DateTime(arg.getTimekey());
              DateTime startShowingDate = timekey.minusDays(tab.getDayLimit());

              /* This is the filtering for events in the future */
              return now.isAfter(startShowingDate) && now.isBefore(timekey);
            }

            public String toString() {
              return "DayLimit Filter: is timekey after now ("
                  + now.toString()
                  + ") and timekey + daylimit is before now?";
            }
          };

    } else if (tab.getDayLimit() < 0) {
      out =
          new UnaryFunctor<Individual, Boolean>() {
            public Boolean fn(Individual arg) {
              if (arg.getSunrise() == null) return Boolean.FALSE;

              DateTime sunrise = new DateTime(arg.getSunrise());
              DateTime stopShowingDate = sunrise.plusDays(Math.abs(tab.getDayLimit()));

              /* This is the filtering for press releases */
              return (sunrise.isBefore(now) || sunrise.isEqual(now))
                  && now.isBefore(stopShowingDate);
            }

            public String toString() {
              return "Sunrise Filter: is sunrise before now and"
                  + " days between now and sunrise greater than or eq to daylimit?";
            }
          };
    }

    return out;
  }