Browse Source

More relative time improvements & fixes

widgets
Ezerous 5 years ago
parent
commit
0322322dde
  1. 8
      app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java
  2. 8
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParser.java
  3. 4
      app/src/test/java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java
  4. 1
      app/src/test/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParserTest.java

8
app/src/main/java/gr/thmmy/mthmmy/utils/DateTimeUtils.java

@ -45,8 +45,12 @@ public class DateTimeUtils {
count = duration/HOUR_IN_MILLIS; count = duration/HOUR_IN_MILLIS;
format = "%dh"; format = "%dh";
mod = (duration%HOUR_IN_MILLIS)/MINUTE_IN_MILLIS; mod = (duration%HOUR_IN_MILLIS)/MINUTE_IN_MILLIS;
if(count<4 && mod>10 && mod<50) if(count<3 && mod>9 && mod<51){
format = format + mod +"m"; if(count==0)
format = mod +"m";
else
format = format + " " + mod +"m";
}
else if(mod >= 30) else if(mod >= 30)
count += 1; count += 1;
} else if (duration < 26*DAY_IN_MILLIS) { } else if (duration < 26*DAY_IN_MILLIS) {

8
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; thmmyDateTime = (new DateTime()).toString("MMMM d, Y, ") + thmmyDateTime;
//Don't even ask //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 // For the stupid format 23:54:12 pm
Matcher matcher = pattern.matcher(thmmyDateTime); Matcher matcher = pattern.matcher(thmmyDateTime);
@ -77,7 +78,10 @@ public class ThmmyDateTimeParser {
return null; 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 @VisibleForTesting

4
app/src/test/java/gr/thmmy/mthmmy/utils/DateTimeUtilsTest.java

@ -31,9 +31,9 @@ public class DateTimeUtilsTest {
"2m", "2m",
"3m", "3m",
"1h", "1h",
"1h15m", "1h 15m",
"2h", "2h",
"3h20m", "3h 20m",
"4h", "4h",
"20h", "20h",
"21h", "21h",

1
app/src/test/java/gr/thmmy/mthmmy/utils/parsing/ThmmyDateTimeParserTest.java

@ -69,6 +69,7 @@ public class ThmmyDateTimeParserTest {
private final String [] todayDateTimes = { private final String [] todayDateTimes = {
"10:10:10", "10:10:10",
"00:58:07",
"23:23:23", "23:23:23",
"09:09:09 am", "09:09:09 am",
"09:09:09 pm" "09:09:09 pm"

Loading…
Cancel
Save