From 7ca2725540cc0c7477137524c2d66437976a3b7d Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Mon, 13 Apr 2020 12:21:19 -0500 Subject: [PATCH] v9.2.2-rc20 - Possible fix for time-based criteria. --- VERSION | 2 +- farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex | 8 +++++--- farmbot_core/test/asset/criteria_retriever_test.exs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 82aec3ad..38ac43e1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -9.2.2-rc20 +9.2.2-rc21 diff --git a/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex b/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex index db77e21a..ebb927ea 100644 --- a/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex +++ b/farmbot_core/lib/farmbot_core/asset/criteria_retriever.ex @@ -138,10 +138,12 @@ defmodule FarmbotCore.Asset.CriteriaRetriever do { pg, accum } else - op = day_criteria["op"] || "<" - time = Timex.shift(Timex.now(), days: -1 * days) + op = day_criteria["op"] || ">" + time = Timex.shift(Timex.now(), days: days) - { pg, accum ++ [{"created_at", op, time}] } + inverted_op = if op == ">" do "<" else ">" end + + { pg, accum ++ [{"created_at", inverted_op, time}] } end end diff --git a/farmbot_core/test/asset/criteria_retriever_test.exs b/farmbot_core/test/asset/criteria_retriever_test.exs index 8d08c9e9..c316b60d 100644 --- a/farmbot_core/test/asset/criteria_retriever_test.exs +++ b/farmbot_core/test/asset/criteria_retriever_test.exs @@ -13,7 +13,7 @@ defmodule FarmbotCore.Asset.CriteriaRetrieverTest do @fake_point_group %PointGroup{ criteria: %{ - "day" => %{"op" => "<", "days_ago" => 4}, + "day" => %{"op" => ">", "days_ago" => 4}, "string_eq" => %{ "openfarm_slug" => ["five", "nine"], "meta.created_by" => ["plant-detection"]