Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

fix: update date format #698

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import com.wynntils.core.utils.helpers.SimpleRelativeDateFormatter;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Date;

public class TerritoryProfile {

public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd[ ]['T']HH:mm:ss[.SSSSSS]");

String name;
String friendlyName;
Expand Down Expand Up @@ -158,8 +161,9 @@ public TerritoryProfile deserialize(JsonElement json, Type typeOfT, JsonDeserial

Date acquired = null;
try {
acquired = dateFormat.parse(territory.get("acquired").getAsString());
} catch (ParseException e) {
// parse using local time because surrounding code expects this
acquired = Date.from(LocalDateTime.parse(territory.get("acquired").getAsString(), dateFormat).atZone(ZoneId.systemDefault()).toInstant());
} catch (DateTimeParseException e) {
e.printStackTrace();
}
String attacker = null;
Expand Down