toShortString method

String toShortString()

Implementation

String toShortString() {
  print("diff ${this.difference(Date.now()).inDays}");
  return Switcher.of(this.difference(Date.now()))
      .predicate((diff) => daysToYears(diff.inDays) < -1, absDays(daysToYears).format("{} years ago"))
      .predicate((diff) => daysToYears(diff.inDays) > 1, absDays(daysToYears).format("In {} years"))
      .predicate((diff) => daysToYears(diff.inDays) == -1, Methods.value("Last year"))
      .predicate((diff) => daysToYears(diff.inDays) == 1, Methods.value("Next year"))
      .predicate((diff) => daysToMonths(diff.inDays) < -1, absDays(daysToMonths).format("{} months ago"))
      .predicate((diff) => daysToMonths(diff.inDays) > 1, absDays(daysToMonths).format("In {} months"))
      .predicate((diff) => daysToMonths(diff.inDays) == -1, Methods.value("Last month"))
      .predicate((diff) => daysToMonths(diff.inDays) == 1, Methods.value("Next month"))
      .predicate((diff) => daysToWeeks(diff.inDays) < -1, absDays(daysToWeeks).format("{} weeks ago"))
      .predicate((diff) => daysToWeeks(diff.inDays) > 1, absDays(daysToWeeks).format("In {} weeks"))
      .predicate((diff) => daysToWeeks(diff.inDays) == -1, Methods.value("Last week"))
      .predicate((diff) => daysToWeeks(diff.inDays) == 1, Methods.value("Next week"))
      .predicate((diff) => diff.inDays < -1, absDays(Methods.passthrough).format("{} days ago"))
      .predicate((diff) => diff.inDays > 1, absDays(Methods.passthrough).format("In {} days"))
      .predicate((diff) => diff.inDays == -1, Methods.value('Yesterday'))
      .predicate((diff) => diff.inDays == 1, Methods.value('Tomorrow'))
      .orElse('Today');
}