From f2a495a7be1934c3c3541d72360985ceb9e2f5bc Mon Sep 17 00:00:00 2001 From: f43nd1r Date: Thu, 26 Jul 2018 03:26:46 +0200 Subject: [PATCH] Use ZonedDateTime instead of LocalDateTime. Fixes #15 --- src/main/java/com/faendir/acra/model/Report.java | 6 +++--- src/main/java/com/faendir/acra/model/view/VBug.java | 8 ++++---- src/main/java/com/faendir/acra/service/DataService.java | 6 ++---- .../faendir/acra/ui/view/base/statistics/Property.java | 6 +++--- src/main/java/com/faendir/acra/util/TimeSpanRenderer.java | 6 +++--- src/main/java/com/faendir/acra/util/Utils.java | 8 ++++---- 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/faendir/acra/model/Report.java b/src/main/java/com/faendir/acra/model/Report.java index 8dca7d1..d22d987 100644 --- a/src/main/java/com/faendir/acra/model/Report.java +++ b/src/main/java/com/faendir/acra/model/Report.java @@ -32,7 +32,7 @@ import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.Transient; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; /** * @author Lukas @@ -47,7 +47,7 @@ public class Report { private Stacktrace stacktrace; @Type(type = "text") private String content; @Transient private JSONObject jsonObject; - private LocalDateTime date; + private ZonedDateTime date; private String userEmail; @Type(type = "text") private String userComment; private String androidVersion; @@ -86,7 +86,7 @@ public class Report { } @NonNull - public LocalDateTime getDate() { + public ZonedDateTime getDate() { return date; } diff --git a/src/main/java/com/faendir/acra/model/view/VBug.java b/src/main/java/com/faendir/acra/model/view/VBug.java index a80fc2b..8ac9fe1 100644 --- a/src/main/java/com/faendir/acra/model/view/VBug.java +++ b/src/main/java/com/faendir/acra/model/view/VBug.java @@ -19,7 +19,7 @@ package com.faendir.acra.model.view; import com.faendir.acra.model.Bug; import com.querydsl.core.annotations.QueryProjection; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; /** * @author lukas @@ -27,13 +27,13 @@ import java.time.LocalDateTime; */ public class VBug { private final Bug bug; - private final LocalDateTime lastReport; + private final ZonedDateTime lastReport; private final long reportCount; private final int highestVersionCode; private final long userCount; @QueryProjection - public VBug(Bug bug, LocalDateTime lastReport, long reportCount, int highestVersionCode, long userCount) { + public VBug(Bug bug, ZonedDateTime lastReport, long reportCount, int highestVersionCode, long userCount) { this.bug = bug; this.lastReport = lastReport; this.reportCount = reportCount; @@ -49,7 +49,7 @@ public class VBug { return reportCount; } - public LocalDateTime getLastReport() { + public ZonedDateTime getLastReport() { return lastReport; } diff --git a/src/main/java/com/faendir/acra/service/DataService.java b/src/main/java/com/faendir/acra/service/DataService.java index 851e866..b6c3210 100644 --- a/src/main/java/com/faendir/acra/service/DataService.java +++ b/src/main/java/com/faendir/acra/service/DataService.java @@ -56,11 +56,10 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.persistence.EntityManager; -import javax.persistence.Query; import javax.validation.constraints.Size; import java.io.IOException; import java.io.Serializable; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.Collection; @@ -69,7 +68,6 @@ import java.util.Map; import java.util.Optional; import java.util.function.BiFunction; import java.util.function.BooleanSupplier; -import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -288,7 +286,7 @@ public class DataService implements Serializable { @Transactional public void deleteReportsOlderThanDays(@NonNull App app, @NonNull int days) { - new JPADeleteClause(entityManager, report).where(report.stacktrace.bug.app.eq(app).and(report.date.before(LocalDateTime.now().minus(days, ChronoUnit.DAYS)))); + new JPADeleteClause(entityManager, report).where(report.stacktrace.bug.app.eq(app).and(report.date.before(ZonedDateTime.now().minus(days, ChronoUnit.DAYS)))); entityManager.flush(); deleteOrphanBugs(); } diff --git a/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java b/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java index 598b6b3..ffd3e9a 100644 --- a/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java +++ b/src/main/java/com/faendir/acra/ui/view/base/statistics/Property.java @@ -29,7 +29,7 @@ import com.vaadin.ui.Component; import com.vaadin.ui.ComponentContainer; import org.vaadin.risto.stepper.IntStepper; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.function.Function; @@ -91,13 +91,13 @@ class Property, T> { return new Property<>(filterText, comboBox, stringExpression::eq, new PieChart(chartTitle), dataService, stringExpression); } - Property createAgeProperty(String filterText, String chartTitle, DateTimePath dateTimeExpression) { + Property createAgeProperty(String filterText, String chartTitle, DateTimePath dateTimeExpression) { IntStepper stepper = new IntStepper(); stepper.setValue(30); stepper.setMinValue(1); return new Property<>(filterText, stepper, - days -> dateTimeExpression.after(LocalDateTime.now().minus(days, ChronoUnit.DAYS)), + days -> dateTimeExpression.after(ZonedDateTime.now().minus(days, ChronoUnit.DAYS)), new TimeChart(chartTitle), dataService, SQLExpressions.date(Date.class, dateTimeExpression)); diff --git a/src/main/java/com/faendir/acra/util/TimeSpanRenderer.java b/src/main/java/com/faendir/acra/util/TimeSpanRenderer.java index 16f99e9..1ef7aee 100644 --- a/src/main/java/com/faendir/acra/util/TimeSpanRenderer.java +++ b/src/main/java/com/faendir/acra/util/TimeSpanRenderer.java @@ -22,7 +22,7 @@ import elemental.json.JsonValue; import org.springframework.lang.Nullable; import org.xbib.time.pretty.PrettyTime; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.util.Locale; /** @@ -32,8 +32,8 @@ import java.util.Locale; public class TimeSpanRenderer extends TextRenderer { @Override public JsonValue encode(@Nullable Object value) { - if (value instanceof LocalDateTime) { - return Json.create(new PrettyTime(Locale.US).formatUnrounded((LocalDateTime) value)); + if (value instanceof ZonedDateTime) { + return Json.create(new PrettyTime(Locale.US).formatUnrounded(((ZonedDateTime) value).toLocalDateTime())); } return super.encode(value); } diff --git a/src/main/java/com/faendir/acra/util/Utils.java b/src/main/java/com/faendir/acra/util/Utils.java index 0363608..85a3b33 100644 --- a/src/main/java/com/faendir/acra/util/Utils.java +++ b/src/main/java/com/faendir/acra/util/Utils.java @@ -30,7 +30,7 @@ import java.io.PrintWriter; import java.io.Reader; import java.io.StringReader; import java.io.StringWriter; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; import java.util.ArrayList; @@ -48,11 +48,11 @@ public final class Utils { private static final Log log = LogFactory.getLog(Utils.class); @NonNull - public static LocalDateTime getDateFromString(@NonNull String s) { + public static ZonedDateTime getDateFromString(@NonNull String s) { try { - return LocalDateTime.parse(s, formatter); + return ZonedDateTime.parse(s, formatter); } catch (DateTimeParseException e) { - return LocalDateTime.now(); + return ZonedDateTime.now(); } }