diff options
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java new file mode 100644 index 000000000..515afec78 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/upcomingcards/UpcomingCardsUtil.java @@ -0,0 +1,38 @@ +package it.niedermann.nextcloud.deck.ui.upcomingcards; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.time.Instant; +import java.time.LocalDate; +import java.time.ZoneId; + +import static java.time.temporal.ChronoUnit.DAYS; + +public class UpcomingCardsUtil { + + private UpcomingCardsUtil() { + throw new UnsupportedOperationException("This class must not get instantiated"); + } + + @NonNull + public static EUpcomingDueType getDueType(@Nullable Instant dueDate) { + if (dueDate == null) { + return EUpcomingDueType.NO_DUE; + } + + long diff = DAYS.between(LocalDate.now(), dueDate.atZone(ZoneId.systemDefault()).toLocalDate()); + + if (diff > 7) { + return EUpcomingDueType.LATER; + } else if (diff > 1) { + return EUpcomingDueType.WEEK; + } else if (diff > 0) { + return EUpcomingDueType.TOMORROW; + } else if (diff == 0) { + return EUpcomingDueType.TODAY; + } else { + return EUpcomingDueType.OVERDUE; + } + } +} |