From 0322322ddecfb0e2040ae7ec061dbd0966946305 Mon Sep 17 00:00:00 2001 From: Ezerous Date: Mon, 7 Oct 2019 21:02:57 +0300 Subject: [PATCH] More relative time improvements & fixes --- .../main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java | 8 ++++++-- .../thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java | 8 ++++++-- .../java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java | 4 ++-- .../mthmmy/utils/parsing/ThmmyDateTimeParserTest.java | 1 + 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java b/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java index a758769d..b5c5528e 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java +++ b/app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java @@ -45,8 +45,12 @@ public class DateTimeUtils { count = duration/HOUR_IN_MILLIS; format = "%dh"; mod = (duration%HOUR_IN_MILLIS)/MINUTE_IN_MILLIS; - if(count<4 && mod>10 && mod<50) - format = format + mod +"m"; + if(count<3 && mod>9 && mod<51){ + if(count==0) + format = mod +"m"; + else + format = format + " " + mod +"m"; + } else if(mod >= 30) count += 1; } else if (duration < 26*DAY_IN_MILLIS) { 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 3780582d..e0f8da2b 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 @@ -52,7 +52,8 @@ public class ThmmyDateTimeParser { thmmyDateTime = (new DateTime()).toString("MMMM d, Y, ") + thmmyDateTime; //Don't even ask - thmmyDateTime = thmmyDateTime.replaceAll("\\s00:"," 12:"); + if(thmmyDateTime.contains("am")) + thmmyDateTime = thmmyDateTime.replaceAll("\\s00:"," 12:"); // For the stupid format 23:54:12 pm Matcher matcher = pattern.matcher(thmmyDateTime); @@ -77,7 +78,10 @@ public class ThmmyDateTimeParser { return null; } } - return Long.toString(dateTime.getMillis()); + String timestamp = Long.toString(dateTime.getMillis()); + Timber.d("DateTime %s was converted to %s, or %s", originalDateTime, timestamp, dateTime.toString()); + + return timestamp; } @VisibleForTesting diff --git a/app/src/test/java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java b/app/src/test/java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java index 1a3eaa2b..5d08eb0e 100644 --- a/app/src/test/java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java +++ b/app/src/test/java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java @@ -31,9 +31,9 @@ public class DateTimeUtilsTest { "2m", "3m", "1h", - "1h15m", + "1h 15m", "2h", - "3h20m", + "3h 20m", "4h", "20h", "21h", 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 e573b274..a9bd02d8 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 @@ -69,6 +69,7 @@ public class ThmmyDateTimeParserTest { private final String [] todayDateTimes = { "10:10:10", + "00:58:07", "23:23:23", "09:09:09 am", "09:09:09 pm"