Skip to content

Commit

Permalink
Previous fix was incorrect.
Browse files Browse the repository at this point in the history
Timestamp doesn't contain date info, therefore we need to construct it
and adjust it if daylight savings applies.

Change-Id: Ic6b5b3e2d773f637a99a80ef0998ee4f9989a8eb
  • Loading branch information
Cuong committed Jun 10, 2012
1 parent ff10e99 commit 52fbb5b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion services/java/com/android/server/location/NMEAParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

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;
Expand All @@ -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;
Expand Down Expand Up @@ -158,8 +162,14 @@ public Location getLocation() {
*/
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;
Expand Down

0 comments on commit 52fbb5b

Please sign in to comment.