Skip to content

Commit

Permalink
Handle observations with no timestamp at all
Browse files Browse the repository at this point in the history
  • Loading branch information
rcloran committed May 4, 2023
1 parent 2755ff2 commit 4362436
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lr-inaturalist-publish.lrdevplugin/SyncObservations.lua
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ local function observationTime(observation)

-- Some (older) observations don't have a time_observed_at, and are only
-- day resolution.
return observation.observed_on_details.date
if observation.observed_on_details then
return observation.observed_on_details.date
end

-- Some observations have no observation time at all.
return nil
end

local function makePhotoSearchQuery(observation)
Expand All @@ -340,7 +345,7 @@ local function makePhotoSearchQuery(observation)
-- timezoneless timestamp matches.
local timeObserved = observationTime(observation)
logger:tracef(" Observation timestamp: %s", timeObserved)
if #timeObserved == 19 and timeObserved:sub(-2, -1) == "00" then
if timeObserved and #timeObserved == 19 and timeObserved:sub(-2, -1) == "00" then
-- Observations created with the web interface only have minute
-- granulatiry. Fortunately the LR date search uses a prefix
-- match (compare a search for "2023-04-01T14:1" with
Expand All @@ -354,12 +359,15 @@ local function makePhotoSearchQuery(observation)
operation = "==",
value = observation.uuid,
},
{
}

if timeObserved then
r[#r + 1] = {
criteria = "captureTime",
operation = "==",
value = timeObserved,
},
}
}
end

return r
end
Expand Down

0 comments on commit 4362436

Please sign in to comment.