Example usage for org.joda.time DateMidnight withDayOfYear

List of usage examples for org.joda.time DateMidnight withDayOfYear

Introduction

In this page you can find the example usage for org.joda.time DateMidnight withDayOfYear.

Prototype

public DateMidnight withDayOfYear(int dayOfYear) 

Source Link

Document

Returns a copy of this date with the day of year field updated.

Usage

From source file:ru.org.linux.tag.TagPageController.java

License:Apache License

private static ImmutableListMultimap<String, Topic> datePartition(Iterable<Topic> topics,
        final Function<Topic, DateTime> dateExtractor) {
    final DateMidnight startOfToday = new DateMidnight();
    final DateMidnight startOfYesterday = startOfToday.minusDays(1);
    final DateMidnight startOfYear = startOfToday.withDayOfYear(1);

    return Multimaps.index(topics, new Function<Topic, String>() {
        @Override//  w ww.  j a  v  a  2s .  c  om
        public String apply(Topic input) {
            DateTime date = dateExtractor.apply(input);

            if (date.isAfter(startOfToday)) {
                return "?";
            } else if (date.isAfter(startOfYesterday)) {
                return "";
            } else if (date.isAfter(startOfYear)) {
                return THIS_YEAR_FORMAT.print(date);
            } else {
                return OLD_YEAR_FORMAT.print(date);
            }
        }
    });
}