@Override
  public String convert(LocalDateTime dateTime) {
    LocalDateTime now = LocalDateTime.now();
    Duration duration = Duration.between(dateTime, now);

    Period period = Period.between(dateTime.toLocalDate(), now.toLocalDate());

    if (duration.toMinutes() < 1) {
      return String.format("%s secs ago", duration.getSeconds());
    }

    if (duration.toHours() < 1) {
      return String.format("%s mins ago", duration.toMinutes());
    }

    if (duration.toDays() < 1) {
      return String.format("%s hrs ago", duration.toHours());
    }

    if (period.getYears() > 0) {
      return DateTimeFormatter.ISO_LOCAL_DATE.format(dateTime);
    }

    if (period.getMonths() > 0) {
      return String.format("%s months ago", period.getMonths());
    }

    return String.format("%s days ago", period.getDays());
  }
예제 #2
0
  void storeXml(ParseIndexContext ctx, Path xml) throws IOException {
    Files.createFile(xml);
    PrintWriter p = new PrintWriter(Files.newBufferedWriter(xml, utf8));
    p.print("<?xml version='1.1' encoding='" + NotesRetriever.utf8.name() + "'?><snotes>");

    ctx.list.sort(Comparator.comparing(o1 -> o1.number));
    for (NoteListItem i : ctx.list) {
      p.print("\n<n");
      p.print(" n='" + i.number + "'");
      if (i.mark != null) p.print(" m='" + i.mark + "'");
      p.print(" a='" + i.apparea + "'");
      p.print(" l='" + i.asklangu + "'");
      p.print(" d='" + DateTimeFormatter.ISO_LOCAL_DATE.format(i.date) + "'");
      p.print(" c='" + i.category + "'");
      p.print(" p='" + i.priority + "'");
      if (i.objid != null) p.print(" o='" + i.objid + "'");
      p.print(">" + StringEscapeUtils.escapeXml11(i.title) + "</n>");
    }
    p.flush();
    for (Pair<String, String> a : ctx.lareas) {
      p.print("\n<area rcode='" + a.getKey() + "' value='" + a.getValue() + "'/>");
    }
    p.flush();
    //		p.print("\n<!-- [Statistics]");
    //		if (dsd==0 && dod==0) {
    //			p.print("\tNotes collected: " + q + ", no duplicates found");
    //		} else {
    //			p.print("\nUnique notes collected: " + q);
    //			p.print("\nDuplicate notes with the same date: " + dsd);
    //			p.print("\nDuplocate notes with the other date: " + dod);
    //		}
    //		p.println("\t-->");
    p.print("\n</snotes>");
    p.close();
  }
 @Override
 public void serialize(LocalDate date, JsonGenerator gen, SerializerProvider serializers)
     throws IOException {
   gen.writeString(DateTimeFormatter.ISO_LOCAL_DATE.format(date));
 }