diff --git a/src/PamUtils/PamCalendar.java b/src/PamUtils/PamCalendar.java index 8a43bb74..3ce2eebc 100644 --- a/src/PamUtils/PamCalendar.java +++ b/src/PamUtils/PamCalendar.java @@ -83,7 +83,8 @@ public class PamCalendar { * viewPositions which is the number of milliseconds from the sessionsStartTime. */ private static long viewPosition; - + + /** * If files are being analysed, return the time based on the file * position. Otherwise just take the normal system time. diff --git a/src/generalDatabase/SQLTypes.java b/src/generalDatabase/SQLTypes.java index b8746472..a81edd89 100644 --- a/src/generalDatabase/SQLTypes.java +++ b/src/generalDatabase/SQLTypes.java @@ -337,11 +337,30 @@ public class SQLTypes { * @return Appropriate object (Generally TimeStamp, but SWLite uses Long) */ public Object getTimeStamp(Long timeMillis) { + /** + * This has just got nasty WRT time zones. + * When the TimeStamp is written to database it uses the default time zone correction, which of course + * I don't want since I only do UTC. I was therefore subtracting this off before creating the ts + * so that it all worked fine when it was added back on again. + * This was fine for many years until someone processed data from exactly when the clocks went + * forward in the spring. Because the data were just after the clocks going forward, it took off + * an hour, then failed to add it back on again since the time was now before daylight saving. + * Amazed this has never happened before. Well done G and E ! I can fix it by setting the + * default time zone to UTC when PAMGuard starts, but note that all future references to local time + * will then be UTC. If I try to change it temporarily it doesn't help since the Timestamp always + * goes to the default, so it needs to be on UTC at the moment data are written to the database, not + * just in this function. + */ if (timeMillis == null) { return null; } - TimeZone tz = TimeZone.getDefault(); - return new Timestamp(timeMillis - tz.getOffset(timeMillis)); +// TimeZone tz = TimeZone.getDefault(); +// TimeZone.setDefault(PamCalendar.defaultTimeZone); +// Timestamp ts = new Timestamp(timeMillis - tz.getOffset(timeMillis)); + Timestamp ts = new Timestamp(timeMillis); +// TimeZone.setDefault(tz); +// Timestamp newTS = ts.toLocalDateTime(); + return ts; } /** diff --git a/src/pamguard/Pamguard.java b/src/pamguard/Pamguard.java index c955192a..d5825b26 100644 --- a/src/pamguard/Pamguard.java +++ b/src/pamguard/Pamguard.java @@ -33,6 +33,7 @@ import PamController.pamBuoyGlobals; import PamController.command.TerminalController; import PamModel.SMRUEnable; import PamUtils.FileFunctions; +import PamUtils.PamCalendar; import PamUtils.PamExceptionHandler; import PamUtils.PlatformInfo; import PamUtils.Splash; @@ -134,6 +135,8 @@ public class Pamguard { Thread folderSizeThread = new Thread(folderSizeMon); folderSizeThread.start(); + TimeZone.setDefault(PamCalendar.defaultTimeZone); + System.out.println("**********************************************************"); try { // get the java runnable file name.