aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2012-03-22 23:34:32 +0100
committerHerbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com>2012-03-23 00:28:22 +0100
commit554287d89b230ed1a73d281a910fd233963a15ea (patch)
tree6f1838ed82c73b78eed616527d6bc8c18ce02ccb /src
parent0bbe9effbb5ed58173bdebdbed74a65c712ec07a (diff)
downloadBlueGPS-554287d89b230ed1a73d281a910fd233963a15ea.zip
BlueGPS-554287d89b230ed1a73d281a910fd233963a15ea.tar.gz
BlueGPS-554287d89b230ed1a73d281a910fd233963a15ea.tar.bz2
Bug correction: bug #9 Handle NMEA timestamps without fractional seconds.
Diffstat (limited to 'src')
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
index 8b70d50..7c361a9 100644
--- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
@@ -22,6 +22,7 @@ package org.broeuschmeul.android.gps.nmea.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -527,16 +528,17 @@ public class NmeaParser {
}
public long parseNmeaTime(String time){
long timestamp = 0;
- SimpleDateFormat fmt = new SimpleDateFormat("HHmmss.S");
+ SimpleDateFormat fmt = new SimpleDateFormat("HHmmss.SSS");
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
try {
if (time != null && time != null){
long now = System.currentTimeMillis();
long today = now - (now %86400000L);
long temp1;
- temp1 = fmt.parse(time).getTime();
+ // sometime we don't have millisecond in the time string, so we have to reformat it
+ temp1 = fmt.parse(String.format((Locale)null,"%010.3f", Double.parseDouble(time))).getTime();
long temp2 = today+temp1;
- //
+ // if we're around midnight we could have a problem...
if (temp2 - now > 43200000L) {
timestamp = temp2 - 86400000L;
} else if (now - temp2 > 43200000L){