From b93a153b2397bb676d54fc19e9883e951a38d56b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 16 Aug 2017 19:33:41 +0200 Subject: [PATCH] parse 12h format properly --- app/src/main/java/info/nightscout/utils/DateUtil.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/utils/DateUtil.java b/app/src/main/java/info/nightscout/utils/DateUtil.java index b058450512..bf2c1ba1fd 100644 --- a/app/src/main/java/info/nightscout/utils/DateUtil.java +++ b/app/src/main/java/info/nightscout/utils/DateUtil.java @@ -85,12 +85,16 @@ public class DateUtil { } public static int toSeconds(String hh_colon_mm) { - Pattern p = Pattern.compile("(\\d+):(\\d+)"); + Pattern p = Pattern.compile("(\\d+):(\\d+)( a.m.| p.m.|)"); Matcher m = p.matcher(hh_colon_mm); int retval = 0; if (m.find()) { retval = SafeParse.stringToInt(m.group(1)) * 60 * 60 + SafeParse.stringToInt(m.group(2)) * 60; + if (m.group(3).equals(" .a.m") && m.group(1).equals("12")) + retval -= 12 * 60 * 60; + if (m.group(3).equals(" p.m.") && !m.group(1).equals("12")) + retval += 12 * 60 * 60; } return retval; }