From 107c4206484c011612da9eae26500db76a75ce95 Mon Sep 17 00:00:00 2001 From: Terry Mancey Date: Wed, 30 Oct 2024 16:25:33 -0500 Subject: [PATCH] =?UTF-8?q?[ads]=20Add=20SmartNTT=20[T=E2=89=A0]=20epoch?= =?UTF-8?q?=20operator=20conditon=20matcher?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epoch_operator_condition_matcher_util.cc | 5 +++++ ...perator_condition_matcher_util_unittest.cc | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc index a2c00bb25a32..c021283e94b9 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util.cc @@ -18,6 +18,7 @@ namespace brave_ads { namespace { constexpr char kEqualOperatorConditionMatcherPrefix[] = "[T=]:"; +constexpr char kNotEqualOperatorConditionMatcherPrefix[] = "[T≠]:"; constexpr char kGreaterThanOperatorConditionMatcherPrefix[] = "[T>]:"; constexpr char kGreaterThanOrEqualOperatorConditionMatcherPrefix[] = "[T≥]:"; constexpr char kLessThanOperatorConditionMatcherPrefix[] = "[T<]:"; @@ -50,6 +51,10 @@ bool MatchEpochOperator(const std::string_view value, return time_delta->InDays() == days; } + if (condition.starts_with(kNotEqualOperatorConditionMatcherPrefix)) { + return time_delta->InDays() != days; + } + if (condition.starts_with(kGreaterThanOperatorConditionMatcherPrefix)) { return time_delta->InDays() > days; } diff --git a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc index f786cc1afc76..78a8ffbf177b 100644 --- a/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc +++ b/components/brave_ads/core/internal/serving/targeting/condition_matcher/matchers/epoch_operator_condition_matcher_util_unittest.cc @@ -47,6 +47,27 @@ TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, DoNotMatchEqualOperator) { "[T=]:3")); // Event occurred 2 days ago. } +TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchNotEqualOperator) { + // Arrange + AdvanceClockTo(test::TimeFromUTCString("3 October 2024")); + + // Act & Assert + EXPECT_TRUE( + MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/, + "[T≠]:3")); // Event occurred 2 days ago. +} + +TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, + DoNotMatchNotEqualOperator) { + // Arrange + AdvanceClockTo(test::TimeFromUTCString("3 October 2024")); + + // Act & Assert + EXPECT_FALSE( + MatchEpochOperator("13372214400000000" /*1st October 2024 00:00:00 UTC*/, + "[T≠]:2")); // Event occurred 2 days ago. +} + TEST_F(BraveAdsEpochOperatorConditionMatcherUtilTest, MatchGreaterThanOperator) { // Arrange