From e89f0e83d0d4dbf8dc49c48ca2de6f7095cf4f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=A0panger?= Date: Sat, 19 Aug 2023 20:57:10 +0200 Subject: [PATCH] remove TimeFixer.java, set datetimeformat timezone to UTC --- .../database/SeedlinkCommunicator.java | 21 ++++++++++++------- .../database/StationDatabaseManager.java | 1 + .../java/globalquake/utils/TimeFixer.java | 11 ---------- 3 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 src/main/java/globalquake/utils/TimeFixer.java diff --git a/src/main/java/globalquake/database/SeedlinkCommunicator.java b/src/main/java/globalquake/database/SeedlinkCommunicator.java index 882de39c3..5e2fd08ba 100644 --- a/src/main/java/globalquake/database/SeedlinkCommunicator.java +++ b/src/main/java/globalquake/database/SeedlinkCommunicator.java @@ -1,7 +1,6 @@ package globalquake.database; import edu.sc.seis.seisFile.seedlink.SeedlinkReader; -import globalquake.utils.TimeFixer; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -13,11 +12,17 @@ import java.io.StringReader; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.TimeZone; public class SeedlinkCommunicator { - private static final SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static final SimpleDateFormat format3 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSSS"); + private static final SimpleDateFormat FORMAT_UTC_SHORT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final SimpleDateFormat FORMAT_UTC_LONG = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSSS"); + + static{ + FORMAT_UTC_SHORT.setTimeZone(TimeZone.getTimeZone("UTC")); + FORMAT_UTC_LONG.setTimeZone(TimeZone.getTimeZone("UTC")); + } public static void runAvailabilityCheck(SeedlinkNetwork seedlinkNetwork, StationDatabase stationDatabase) throws Exception { seedlinkNetwork.getStatus().setString("Connecting..."); @@ -57,11 +62,11 @@ private static void parseAvailability(String infoString, StationDatabase station String channelName = channel.getAttributes().getNamedItem("seedname").getTextContent(); String endDate = channel.getAttributes().getNamedItem("end_time").getTextContent(); Calendar end = Calendar.getInstance(); - end.setTime(endDate.contains("-") ? format2.parse(endDate) : format3.parse(endDate)); - long delay = System.currentTimeMillis() - end.getTimeInMillis() - TimeFixer.offset(); - if (delay > 1000 * 60 * 15) { - continue; - } + end.setTime(endDate.contains("-") ? FORMAT_UTC_SHORT.parse(endDate) : FORMAT_UTC_LONG.parse(endDate)); + + long delay = System.currentTimeMillis() - end.getTimeInMillis(); + System.out.println(delay); + addAvailableChannel(networkCode, stationCode, channelName, locationCode, delay, seedlinkNetwork, stationDatabase); } } diff --git a/src/main/java/globalquake/database/StationDatabaseManager.java b/src/main/java/globalquake/database/StationDatabaseManager.java index 8b9715701..7b6c9e027 100644 --- a/src/main/java/globalquake/database/StationDatabaseManager.java +++ b/src/main/java/globalquake/database/StationDatabaseManager.java @@ -175,6 +175,7 @@ public void runAvailabilityCheck(List toBeUpdated, Runnable onF SeedlinkCommunicator.runAvailabilityCheck(seedlinkNetwork, stationDatabase); break; } catch (Exception e) { + e.printStackTrace(); seedlinkNetwork.getStatus().setString("Error!"); seedlinkNetwork.getStatus().setValue(0); } finally { diff --git a/src/main/java/globalquake/utils/TimeFixer.java b/src/main/java/globalquake/utils/TimeFixer.java deleted file mode 100644 index 5c3c25d51..000000000 --- a/src/main/java/globalquake/utils/TimeFixer.java +++ /dev/null @@ -1,11 +0,0 @@ -package globalquake.utils; - -import java.util.TimeZone; - -public class TimeFixer { - - public static long offset() { - return TimeZone.getTimeZone("CET").getOffset(System.currentTimeMillis()); - } - -}