From dfcd6b2171bd74878742b48080f443acc89b91da Mon Sep 17 00:00:00 2001 From: Ricardo Campos Date: Wed, 9 Oct 2024 12:27:18 -0300 Subject: [PATCH] fix: npe when formatting --- .../main/java/br/com/tasknoteapp/server/util/TimeAgoUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/src/main/java/br/com/tasknoteapp/server/util/TimeAgoUtil.java b/server/src/main/java/br/com/tasknoteapp/server/util/TimeAgoUtil.java index 99cd16e..8ab2597 100644 --- a/server/src/main/java/br/com/tasknoteapp/server/util/TimeAgoUtil.java +++ b/server/src/main/java/br/com/tasknoteapp/server/util/TimeAgoUtil.java @@ -3,6 +3,7 @@ package br.com.tasknoteapp.server.util; import java.time.Duration; import java.time.LocalDateTime; import java.time.Period; +import java.util.Objects; /** This class contains util methods to format local date time. */ public class TimeAgoUtil { @@ -14,6 +15,9 @@ public class TimeAgoUtil { * @return String with formatted time. */ public static String format(LocalDateTime pastTime) { + if (Objects.isNull(pastTime)) { + return "Some time ago"; + } LocalDateTime now = LocalDateTime.now(); Period period = Period.between(pastTime.toLocalDate(), now.toLocalDate()); Duration duration = Duration.between(pastTime, now);