mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
Allow different timestamp formats in Google exports to be parsed
This commit is contained in:
parent
0727bed62f
commit
6077776880
2 changed files with 35 additions and 5 deletions
|
|
@ -35,10 +35,25 @@ class GoogleMaps::RecordsParser
|
|||
{
|
||||
latitude: json['latitudeE7'].to_f / 10**7,
|
||||
longitude: json['longitudeE7'].to_f / 10**7,
|
||||
timestamp: DateTime.parse(json['timestamp']).to_i,
|
||||
timestamp: parse_timestamp(json['timestamp'] || json['timestampMs']),
|
||||
altitude: json['altitude'],
|
||||
velocity: json['velocity'],
|
||||
raw_data: json
|
||||
}
|
||||
end
|
||||
|
||||
def parse_timestamp(timestamp)
|
||||
begin
|
||||
# if the timestamp is in ISO 8601 format, try to parse it
|
||||
DateTime.parse(timestamp).to_time.to_i
|
||||
rescue
|
||||
if timestamp.to_s.length > 10
|
||||
# If the timestamp is in milliseconds, convert to seconds
|
||||
timestamp.to_i / 1000
|
||||
else
|
||||
# If the timestamp is in seconds, return it without change
|
||||
timestamp.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class GoogleMaps::SemanticHistoryParser
|
|||
{
|
||||
latitude: waypoint['latE7'].to_f / 10**7,
|
||||
longitude: waypoint['lngE7'].to_f / 10**7,
|
||||
timestamp: DateTime.parse(timeline_object['activitySegment']['duration']['startTimestamp']).to_i,
|
||||
timestamp: parse_timestamp(timeline_object['activitySegment']['duration']['startTimestamp'] || timeline_object['activitySegment']['duration']['startTimestampMs']),
|
||||
raw_data: timeline_object
|
||||
}
|
||||
end
|
||||
|
|
@ -52,7 +52,7 @@ class GoogleMaps::SemanticHistoryParser
|
|||
{
|
||||
latitude: timeline_object['activitySegment']['startLocation']['latitudeE7'].to_f / 10**7,
|
||||
longitude: timeline_object['activitySegment']['startLocation']['longitudeE7'].to_f / 10**7,
|
||||
timestamp: DateTime.parse(timeline_object['activitySegment']['duration']['startTimestamp']),
|
||||
timestamp: parse_timestamp(timeline_object['activitySegment']['duration']['startTimestamp'] || timeline_object['activitySegment']['duration']['startTimestampMs']),
|
||||
raw_data: timeline_object
|
||||
}
|
||||
end
|
||||
|
|
@ -62,7 +62,7 @@ class GoogleMaps::SemanticHistoryParser
|
|||
{
|
||||
latitude: timeline_object['placeVisit']['location']['latitudeE7'].to_f / 10**7,
|
||||
longitude: timeline_object['placeVisit']['location']['longitudeE7'].to_f / 10**7,
|
||||
timestamp: DateTime.parse(timeline_object['placeVisit']['duration']['startTimestamp']),
|
||||
timestamp: parse_timestamp(timeline_object['placeVisit']['duration']['startTimestamp'] || timeline_object['placeVisit']['duration']['startTimestampMs']),
|
||||
raw_data: timeline_object
|
||||
}
|
||||
elsif timeline_object['placeVisit']['otherCandidateLocations'].any?
|
||||
|
|
@ -73,7 +73,7 @@ class GoogleMaps::SemanticHistoryParser
|
|||
{
|
||||
latitude: point['latitudeE7'].to_f / 10**7,
|
||||
longitude: point['longitudeE7'].to_f / 10**7,
|
||||
timestamp: DateTime.parse(timeline_object['placeVisit']['duration']['startTimestamp']),
|
||||
timestamp: parse_timestamp(timeline_object['placeVisit']['duration']['startTimestamp'] || timeline_object['placeVisit']['duration']['startTimestampMs']),
|
||||
raw_data: timeline_object
|
||||
}
|
||||
else
|
||||
|
|
@ -82,4 +82,19 @@ class GoogleMaps::SemanticHistoryParser
|
|||
end
|
||||
end.reject(&:blank?)
|
||||
end
|
||||
|
||||
def parse_timestamp(timestamp)
|
||||
begin
|
||||
# if the timestamp is in ISO 8601 format, try to parse it
|
||||
DateTime.parse(timestamp).to_time.to_i
|
||||
rescue
|
||||
if timestamp.to_s.length > 10
|
||||
# If the timestamp is in milliseconds, convert to seconds
|
||||
timestamp.to_i / 1000
|
||||
else
|
||||
# If the timestamp is in seconds, return it without change
|
||||
timestamp.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue