this repo has no description

feature: Added rhai function to compare dates with duration strings

Signed-off-by: Nick Gerakines <12125+ngerakines@users.noreply.github.com>

+43 -1
+42
src/matcher.rs
··· 1 1 use anyhow::{anyhow, Context, Result}; 2 2 3 + use chrono::{DateTime, Utc}; 3 4 use serde_json_path::JsonPath; 4 5 5 6 use rhai::{ ··· 151 152 } 152 153 } 153 154 155 + pub fn matcher_before_duration(duration: &str, date: &str) -> bool { 156 + let parsed_date = DateTime::parse_from_rfc3339(date).map(|v| v.with_timezone(&Utc)); 157 + if let Err(err) = parsed_date { 158 + tracing::debug!(error = ?err, "error parsing date"); 159 + return true; 160 + } 161 + let (direction, parsed_duration) = if let Some(duration) = duration.strip_prefix('-') { 162 + (true, duration_str::parse_chrono(duration)) 163 + } else { 164 + (false, duration_str::parse_chrono(duration)) 165 + }; 166 + 167 + if let Err(err) = parsed_duration { 168 + tracing::debug!(error = ?err, "error parsing date"); 169 + return true; 170 + } 171 + 172 + let date = parsed_date.unwrap(); 173 + let duration = parsed_duration.unwrap(); 174 + let target = if direction { 175 + Utc::now() - duration 176 + } else { 177 + Utc::now() + duration 178 + }; 179 + 180 + date < target 181 + } 182 + 154 183 pub struct PrefixMatcher { 155 184 prefix: String, 156 185 path: JsonPath, ··· 390 419 .build_type::<Match>() 391 420 .register_fn("build_aturi", build_aturi) 392 421 .register_fn("sequence_matches", matcher_sequence_matches) 422 + .register_fn("matcher_before_duration", matcher_before_duration) 393 423 .register_fn("update_match", Match::update) 394 424 .register_fn("upsert_match", Match::upsert); 395 425 let ast = engine ··· 790 820 } 791 821 792 822 Ok(()) 823 + } 824 + 825 + #[test] 826 + fn matcher_before_duration() { 827 + assert!(super::matcher_before_duration( 828 + "1mon", 829 + "2024-11-15T11:05:01.000Z" 830 + )); 831 + assert!(!super::matcher_before_duration( 832 + "-1mon", 833 + "2024-11-15T11:05:01.000Z" 834 + )); 793 835 } 794 836 }
+1 -1
src/storage.rs
··· 207 207 .await 208 208 .expect("failed to insert record"); 209 209 210 - let records = super::feed_content_paginate(&pool, "feed", None, None) 210 + let records = super::feed_content_cached(&pool, "feed", 5) 211 211 .await 212 212 .expect("failed to paginate records"); 213 213
testdata/atmosphere_dev6.json

This is a binary file and will not be displayed.