@Test public void setSearchResultDateRelatedValues() { SearchResultWebTOBuilder builder = SearchResultWebTO.builder(); SearchResultItem item = new SearchResultItem(); item.setPubDate(Instant.now().minus(100, ChronoUnit.DAYS)); item.setUsenetDate(Instant.now().minus(10, ChronoUnit.DAYS)); builder = testee.setSearchResultDateRelatedValues(builder, item); assertThat(builder.build().getAge()).isEqualTo("10d"); item.setUsenetDate(Instant.now().minus(10, ChronoUnit.HOURS)); builder = testee.setSearchResultDateRelatedValues(builder, item); assertThat(builder.build().getAge()).isEqualTo("10h"); item.setUsenetDate(Instant.now().minus(10, ChronoUnit.MINUTES)); builder = testee.setSearchResultDateRelatedValues(builder, item); assertThat(builder.build().getAge()).isEqualTo("10m"); item.setUsenetDate(null); builder = testee.setSearchResultDateRelatedValues(builder, item); assertThat(builder.build().getAge()).isEqualTo("100d"); }
protected SearchResultWebTOBuilder setSearchResultDateRelatedValues(SearchResultWebTOBuilder builder, SearchResultItem item) { Instant date = item.getBestDate(); long ageInDays = date.until(Instant.now(), ChronoUnit.DAYS); if (ageInDays > 0) { builder.age(ageInDays + "d"); } else { long ageInHours = date.until(Instant.now(), ChronoUnit.HOURS); if (ageInHours > 0) { builder.age(ageInHours + "h"); } else { long ageInMinutes = date.until(Instant.now(), ChronoUnit.MINUTES); builder.age(ageInMinutes + "m"); } } builder = builder .age_precise(item.isAgePrecise()) .date(LocalDateTime.ofInstant(date, ZoneId.of("UTC")).format(item.isAgePrecise() ? DATE_TIME_FORMATTER : DATE_FORMATTER)) .epoch(date.getEpochSecond()); return builder; }
InternalSearchResultProcessor { protected SearchResultWebTOBuilder setSearchResultDateRelatedValues(SearchResultWebTOBuilder builder, SearchResultItem item) { Instant date = item.getBestDate(); long ageInDays = date.until(Instant.now(), ChronoUnit.DAYS); if (ageInDays > 0) { builder.age(ageInDays + "d"); } else { long ageInHours = date.until(Instant.now(), ChronoUnit.HOURS); if (ageInHours > 0) { builder.age(ageInHours + "h"); } else { long ageInMinutes = date.until(Instant.now(), ChronoUnit.MINUTES); builder.age(ageInMinutes + "m"); } } builder = builder .age_precise(item.isAgePrecise()) .date(LocalDateTime.ofInstant(date, ZoneId.of("UTC")).format(item.isAgePrecise() ? DATE_TIME_FORMATTER : DATE_FORMATTER)) .epoch(date.getEpochSecond()); return builder; } }
InternalSearchResultProcessor { protected SearchResultWebTOBuilder setSearchResultDateRelatedValues(SearchResultWebTOBuilder builder, SearchResultItem item) { Instant date = item.getBestDate(); long ageInDays = date.until(Instant.now(), ChronoUnit.DAYS); if (ageInDays > 0) { builder.age(ageInDays + "d"); } else { long ageInHours = date.until(Instant.now(), ChronoUnit.HOURS); if (ageInHours > 0) { builder.age(ageInHours + "h"); } else { long ageInMinutes = date.until(Instant.now(), ChronoUnit.MINUTES); builder.age(ageInMinutes + "m"); } } builder = builder .age_precise(item.isAgePrecise()) .date(LocalDateTime.ofInstant(date, ZoneId.of("UTC")).format(item.isAgePrecise() ? DATE_TIME_FORMATTER : DATE_FORMATTER)) .epoch(date.getEpochSecond()); return builder; }  }
InternalSearchResultProcessor { protected SearchResultWebTOBuilder setSearchResultDateRelatedValues(SearchResultWebTOBuilder builder, SearchResultItem item) { Instant date = item.getBestDate(); long ageInDays = date.until(Instant.now(), ChronoUnit.DAYS); if (ageInDays > 0) { builder.age(ageInDays + "d"); } else { long ageInHours = date.until(Instant.now(), ChronoUnit.HOURS); if (ageInHours > 0) { builder.age(ageInHours + "h"); } else { long ageInMinutes = date.until(Instant.now(), ChronoUnit.MINUTES); builder.age(ageInMinutes + "m"); } } builder = builder .age_precise(item.isAgePrecise()) .date(LocalDateTime.ofInstant(date, ZoneId.of("UTC")).format(item.isAgePrecise() ? DATE_TIME_FORMATTER : DATE_FORMATTER)) .epoch(date.getEpochSecond()); return builder; }  SearchResponse createSearchResponse(org.nzbhydra.searching.SearchResult searchResult); }
InternalSearchResultProcessor { protected SearchResultWebTOBuilder setSearchResultDateRelatedValues(SearchResultWebTOBuilder builder, SearchResultItem item) { Instant date = item.getBestDate(); long ageInDays = date.until(Instant.now(), ChronoUnit.DAYS); if (ageInDays > 0) { builder.age(ageInDays + "d"); } else { long ageInHours = date.until(Instant.now(), ChronoUnit.HOURS); if (ageInHours > 0) { builder.age(ageInHours + "h"); } else { long ageInMinutes = date.until(Instant.now(), ChronoUnit.MINUTES); builder.age(ageInMinutes + "m"); } } builder = builder .age_precise(item.isAgePrecise()) .date(LocalDateTime.ofInstant(date, ZoneId.of("UTC")).format(item.isAgePrecise() ? DATE_TIME_FORMATTER : DATE_FORMATTER)) .epoch(date.getEpochSecond()); return builder; }  SearchResponse createSearchResponse(org.nzbhydra.searching.SearchResult searchResult);  }