bugfix: date-times were displayed @ UTC, not localtime

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-01-27 00:16:33 +01:00
parent 25ad4231c7
commit fe085e503f
9 changed files with 35 additions and 38 deletions

View File

@@ -7,6 +7,7 @@ import static de.srsoftware.tools.PathHandler.GET;
import static de.srsoftware.tools.PathHandler.POST;
import static de.srsoftware.tools.Strings.hex;
import static de.srsoftware.umbrella.core.Errors.INVALID_URL;
import static de.srsoftware.umbrella.core.constants.Constants.TIME_FORMATTER;
import static de.srsoftware.umbrella.core.constants.Field.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.serverError;
import static java.lang.System.Logger.Level.*;
@@ -200,7 +201,7 @@ public class Util {
plantumlJar = file;
}
public static LocalDateTime dateTimeOf(long epocSecs){
return LocalDateTime.ofInstant(Instant.ofEpochSecond(epocSecs), ZoneId.systemDefault());
public static String dateTimeOf(long epochMilis){
return LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMilis), ZoneId.systemDefault()).format(TIME_FORMATTER);
}
}

View File

@@ -21,7 +21,7 @@ public class Constants {
public static final String NO_CACHE = "no-cache";
public static final String NONE = "none";
public static final String TABLE_SETTINGS = "settings";
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
public static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static final String UMBRELLA = "Umbrella";
public static final String UTF8 = UTF_8.displayName();

View File

@@ -10,7 +10,6 @@ import static de.srsoftware.umbrella.core.model.Translatable.t;
import static java.text.MessageFormat.format;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -22,7 +21,6 @@ import org.json.JSONObject;
public class Envelope<T extends Message<?>> {
private final T message;
private final Set<User> receivers;
private LocalDateTime time;
private final long id;
public Envelope(long id, T message, User receiver){
@@ -32,7 +30,6 @@ public class Envelope<T extends Message<?>> {
public Envelope(long id, T message, Collection<? extends User> receivers) {
this.message = message;
this.receivers = new HashSet<>(receivers);
time = LocalDateTime.now();
this.id = id;
}
@@ -60,12 +57,12 @@ public class Envelope<T extends Message<?>> {
@Override
public final boolean equals(Object o) {
if (!(o instanceof Envelope<?> envelope)) return false;
return message.equals(envelope.message) && time.equals(envelope.time);
return message.equals(envelope.message) && id == envelope.id;
}
@Override
public int hashCode() {
return 31 * message.hashCode() + time.hashCode();
return message.hashCode();
}
public long id(){
@@ -84,15 +81,6 @@ public class Envelope<T extends Message<?>> {
return receivers;
}
public Envelope<T> time(LocalDateTime timestamp){
this.time = timestamp;
return this;
}
public LocalDateTime time(){
return time;
}
@Override
public String toString() {
return format("{0} (to: {1}), subject: {2}",getClass().getSimpleName(),receivers.stream().map(User::email).map(EmailAddress::toString).collect(Collectors.joining(", ")),message.subject());

View File

@@ -10,12 +10,14 @@ public abstract class Message<T> {
private final Collection<Attachment> attachments;
private final T body, subject;
private final UmbrellaUser sender;
private long utcTime;
public Message(UmbrellaUser sender, T subject, T body, Collection<Attachment> attachments){
this.sender = sender;
this.subject = subject;
this.body = body;
this.attachments = attachments;
this.utcTime = System.currentTimeMillis();
}
public Collection<Attachment> attachments(){
@@ -49,4 +51,13 @@ public abstract class Message<T> {
public String toString() {
return format("{0}(from: {1}), subject: {2}",getClass().getSimpleName(),sender,subject);
}
public long utcTime() {
return utcTime;
}
public Message<T> utcTime(long newValue){
utcTime = newValue;
return this;
}
}

View File

@@ -9,6 +9,8 @@ public class TranslatableMessage extends Message<Translatable> {
}
public TranslatedMessage translate(String lang){
return new TranslatedMessage(sender(),subject().translate(lang),body().translate(lang),attachments());
var translated = new TranslatedMessage(sender(),subject().translate(lang),body().translate(lang),attachments());
translated.utcTime(this.utcTime());
return translated;
}
}