diff --git a/app/build.gradle b/app/build.gradle index 7405e986..2ae628d2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -96,7 +96,7 @@ dependencies { force = true //TODO: Remove when minSdkVersion >= 21 } implementation 'org.jsoup:jsoup:1.13.1' - implementation 'joda-time:joda-time:2.10.4' + implementation 'joda-time:joda-time:2.10.8' implementation 'com.github.franmontiel:PersistentCookieJar:1.0.1' implementation 'com.github.PhilJay:MPAndroidChart:3.0.3' implementation 'com.mikepenz:materialdrawer:6.1.1' diff --git a/app/src/main/assets/apache_libraries.html b/app/src/main/assets/apache_libraries.html index 2d6e23cb..0d6ba704 100644 --- a/app/src/main/assets/apache_libraries.html +++ b/app/src/main/assets/apache_libraries.html @@ -51,8 +51,8 @@ Andrew Oberstar)
  • -
    Joda-Time v2.10.4 (Copyright - ©2002-2019 Joda.org)
    +
    Joda-Time v2.10.8 (Copyright + ©2002-2020 Joda.org)
  • PowerMock v2.0.2
    diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java index 0d59104c..721c7b40 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java @@ -5,6 +5,8 @@ import androidx.annotation.VisibleForTesting; import org.joda.time.DateTime; import org.joda.time.DateTimeUtils; import org.joda.time.DateTimeZone; +import org.joda.time.IllegalInstantException; +import org.joda.time.LocalDateTime; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.DateTimeFormatterBuilder; @@ -64,8 +66,9 @@ public class ThmmyDateTimeParser { thmmyDateTime = thmmyDateTime.replaceAll("\\spm", ""); DateTime dateTime; + LocalDateTime localDateTime; try { - dateTime = formatter.withZone(dtz).withLocale(englishLocale).parseDateTime(thmmyDateTime); + localDateTime = formatter.withLocale(englishLocale).parseLocalDateTime(thmmyDateTime); } catch (IllegalArgumentException e1) { Timber.v("Parsing DateTime %s using English Locale failed.", thmmyDateTime); try { @@ -73,13 +76,23 @@ public class ThmmyDateTimeParser { thmmyDateTime = thmmyDateTime.replace("am", dfs.getAmPmStrings()[0]); thmmyDateTime = thmmyDateTime.replace("pm", dfs.getAmPmStrings()[1]); Timber.v("Attempting to parse DateTime %s using Greek Locale...", thmmyDateTime); - dateTime = formatter.withZone(dtz).withLocale(greekLocale).parseDateTime(thmmyDateTime); + localDateTime = formatter.withLocale(greekLocale).parseLocalDateTime(thmmyDateTime); } catch (IllegalArgumentException e2) { - Timber.d("Parsing DateTime %s using Greek Locale failed too.", thmmyDateTime); + Timber.v("Parsing DateTime %s using Greek Locale failed too.", thmmyDateTime); Timber.e("Couldn't convert DateTime %s to timestamp!", originalDateTime); return null; } } + + // Ensure DST time overlaps/ gaps are handled properly + try{ + // For autumn overlaps + dateTime = localDateTime.toDateTime(dtz).withEarlierOffsetAtOverlap(); + } catch (IllegalInstantException e2) { + // For spring gaps + dateTime = localDateTime.plusHours(1).toDateTime(dtz); + } + String timestamp = Long.toString(dateTime.getMillis()); Timber.v("DateTime %s was converted to %s, or %s", originalDateTime, timestamp, dateTime.toString()); diff --git a/app/src/test/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParserTest.java b/app/src/test/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParserTest.java index 814326fe..30664fd1 100644 --- a/app/src/test/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParserTest.java +++ b/app/src/test/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParserTest.java @@ -25,7 +25,7 @@ public class ThmmyDateTimeParserTest { private static final String TIME_ZONE = "Europe/Athens"; private static final String GET_DTZ = "getDtz"; - private final String[] expTimestamps = {"1569245936000", "1569191627000", "1570050809000"}; + private final String[] expTimestamps = {"1569245936000", "1569191627000", "1570050809000", "1553995543000"}; private final String[][] dateTimes = { { "Σεπτεμβρίου 23, 2019, 16:38:56", @@ -45,6 +45,9 @@ public class ThmmyDateTimeParserTest { { "Οκτωβρίου 03, 2019, 12:13:29 am", "Οκτωβρίου 03, 2019, 00:13:29 am" + }, + { + "Μαρτίου 31, 2019, 03:25:43 am" } };