Skip to content

Commit 81ccdf8

Browse files
authored
use Location timestamp whenever available (#463)
1 parent 15034aa commit 81ccdf8

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/MapboxEvent.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static Hashtable<String, Object> buildMapClickEvent(
8787

8888
Hashtable<String, Object> evt = new Hashtable<>();
8989
evt.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_MAP_CLICK);
90-
evt.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate());
90+
evt.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(location));
9191
evt.put(MapboxEvent.KEY_GESTURE_ID, gestureId);
9292
evt.put(MapboxEvent.KEY_LATITUDE, location.getLatitude());
9393
evt.put(MapboxEvent.KEY_LONGITUDE, location.getLongitude());
@@ -115,7 +115,7 @@ public static Hashtable<String, Object> buildMapDragEndEvent(
115115

116116
Hashtable<String, Object> evt = new Hashtable<>();
117117
evt.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_MAP_DRAG_END);
118-
evt.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate());
118+
evt.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(location));
119119
evt.put(MapboxEvent.KEY_LATITUDE, location.getLatitude());
120120
evt.put(MapboxEvent.KEY_LONGITUDE, location.getLongitude());
121121
evt.put(MapboxEvent.KEY_ZOOM, zoom);
@@ -128,7 +128,7 @@ public static Hashtable<String, Object> buildMapDragEndEvent(
128128
public static Hashtable<String, Object> buildMapLoadEvent() {
129129
Hashtable<String, Object> evt = new Hashtable<>();
130130
evt.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_MAP_LOAD);
131-
evt.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate());
131+
evt.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(null));
132132
return evt;
133133
}
134134
}

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/MapboxTelemetry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ protected void addLocationEvent(Location location) {
427427
// Add Location even to queue
428428
Hashtable<String, Object> event = new Hashtable<>();
429429
event.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_LOCATION);
430-
event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate());
430+
event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(location));
431431
event.put(MapboxEvent.KEY_SOURCE, MapboxEvent.SOURCE_MAPBOX);
432432
event.put(MapboxEvent.KEY_SESSION_ID, mapboxSessionId);
433433
event.put(MapboxEvent.KEY_LATITUDE, latitudeScaled);
@@ -533,7 +533,7 @@ private void flushEventsQueueImmediately(boolean hasTurnstileEvent) {
533533
private void pushTurnstileEvent() {
534534
Hashtable<String, Object> event = new Hashtable<>();
535535
event.put(MapboxEvent.KEY_EVENT, MapboxEvent.TYPE_TURNSTILE);
536-
event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate());
536+
event.put(MapboxEvent.KEY_CREATED, TelemetryUtils.generateCreateDate(null));
537537
event.put(MapboxEvent.KEY_USER_ID, mapboxVendorId);
538538
event.put(MapboxEvent.KEY_ENABLED_TELEMETRY, isTelemetryEnabled());
539539
events.add(event);

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/utils/TelemetryUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ public class TelemetryUtils {
2727
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ",
2828
TelemetryConstants.DEFAULT_LOCALE);
2929

30-
public static String generateCreateDate() {
31-
return dateFormat.format(new Date());
30+
public static String generateCreateDate(Location location) {
31+
if (location != null) {
32+
// Per docs, all locations generated by the LocationManager are guaranteed to have a valid UTC time.
33+
return dateFormat.format(new Date(location.getTime()));
34+
} else {
35+
return dateFormat.format(new Date());
36+
}
3237
}
3338

3439
public static Location buildLocation(double longitude, double latitude) {

0 commit comments

Comments
 (0)