summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCuong <cuongbui@gmail.com>2012-06-10 20:51:02 +0200
committerDanny Baumann <dannybaumann@web.de>2012-06-11 09:08:00 +0200
commit127e0263220d969d14ada249e980b96511201731 (patch)
treea1040a7578c5152c18256d78a2636d0e105c84a2
parentb873ee2b69747d7f160440ece56ea9cf0d426467 (diff)
downloadandroid_frameworks_base-gb-release-7.2.tar.gz
android_frameworks_base-gb-release-7.2.tar.bz2
android_frameworks_base-gb-release-7.2.zip
Previous fix was incorrect.gb-release-7.2
Timestamp doesn't contain date info, therefore we need to construct it and adjust it if daylight savings applies. Change-Id: Ic6b5b3e2d773f637a99a80ef0998ee4f9989a8eb
-rw-r--r--services/java/com/android/server/location/NMEAParser.java12
1 files changed, 11 insertions, 1 deletions
diff --git a/services/java/com/android/server/location/NMEAParser.java b/services/java/com/android/server/location/NMEAParser.java
index 4acbf263829..c308b1491f1 100644
--- a/services/java/com/android/server/location/NMEAParser.java
+++ b/services/java/com/android/server/location/NMEAParser.java
@@ -18,7 +18,9 @@ package com.android.server.location;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
+import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.TimeZone;
import java.util.regex.Matcher;
@@ -35,6 +37,8 @@ public class NMEAParser {
// NMEA sentence pattern
private final Pattern sentencePattern = Pattern.compile("\\$([^*$]{5,})(\\*\\w{2})?");
private final SimpleDateFormat timeFormatter = new SimpleDateFormat("HHmmss.S");
+ private final TimeZone GPSTimezone = TimeZone.getTimeZone("UTC");
+ private GregorianCalendar GPSCalendar = new GregorianCalendar(GPSTimezone);
private HashMap<String,ParseInterface> parseMap = new HashMap<String,ParseInterface>();
private String provider;
@@ -158,8 +162,14 @@ public class NMEAParser {
*/
private long parseTimeToDate(String time) {
try {
+ // parse time , We only get timestamp from sentences
+ // use UTC calendar to set the date.
Date btTime = timeFormatter.parse(time);
- return btTime.getTime();
+ Calendar localCalendar = Calendar.getInstance(GPSTimezone);
+ GPSCalendar.setTimeInMillis(btTime.getTime());
+ GPSCalendar.set(localCalendar.get(Calendar.YEAR), localCalendar.get(Calendar.MONTH),
+ localCalendar.get(Calendar.DAY_OF_MONTH));
+ return GPSCalendar.getTimeInMillis();
} catch (ParseException e) {
Log.e(TAG, "Could not parse: " + time);
return 0;