File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
crates/extensions/tedge_flows/src Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 1+ use std:: ops:: Sub ;
2+ use std:: time:: Duration ;
3+
14use crate :: js_runtime:: JsRuntime ;
25use crate :: js_script:: JsScript ;
36use crate :: stats:: Counter ;
@@ -239,11 +242,24 @@ impl DateTime {
239242 let tick_every_secs = tick_every. as_secs ( ) ;
240243 tick_every_secs != 0 && ( self . seconds % tick_every_secs == 0 )
241244 }
245+ }
246+
247+ impl Sub < Duration > for DateTime {
248+ type Output = DateTime ;
242249
243- pub fn sub_duration ( & self , duration : std:: time:: Duration ) -> Self {
244- DateTime {
245- seconds : self . seconds - duration. as_secs ( ) ,
246- nanoseconds : self . nanoseconds ,
250+ fn sub ( self , rhs : Duration ) -> Self :: Output {
251+ if rhs. subsec_nanos ( ) > self . nanoseconds {
252+ let seconds = self . seconds - 1 ;
253+ let nanoseconds = self . nanoseconds + 1_000_000_000 - rhs. subsec_nanos ( ) ;
254+ DateTime {
255+ seconds : seconds - rhs. as_secs ( ) ,
256+ nanoseconds,
257+ }
258+ } else {
259+ DateTime {
260+ seconds : self . seconds - rhs. as_secs ( ) ,
261+ nanoseconds : self . nanoseconds - rhs. subsec_nanos ( ) ,
262+ }
247263 }
248264 }
249265}
Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ impl MessageProcessor {
214214 } = & flow. input
215215 {
216216 if timestamp. tick_now ( * input_frequency) {
217- let cutoff_time = timestamp. sub_duration ( * input_span) ;
217+ let cutoff_time = timestamp - * input_span;
218218 let drained_messages = self
219219 . database
220220 . drain_older_than ( cutoff_time, input_series)
You can’t perform that action at this time.
0 commit comments