github.com/argoproj/argo-events@v1.9.1/docs/sensors/filters/time.md (about) 1 2 # Time Filter 3 4 Time filter is applied to the event time, contained in the event context. A CloudEvent from Webhook event-source has payload structure as: 5 6 ```json 7 { 8 "context": { 9 "type": "type_of_event_source", 10 "specversion": "cloud_events_version", 11 "source": "name_of_the_event_source", 12 "id": "unique_event_id", 13 "time": "event_time", 14 "datacontenttype": "type_of_data", 15 "subject": "name_of_the_configuration_within_event_source" 16 }, 17 "data": { 18 "header": {}, 19 "body": {}, 20 } 21 } 22 ``` 23 24 It filters out events occurring outside the specified time range, so it is specially helpful when 25 you need to make sure an event occurs between a certain time-frame. 26 27 ## Fields 28 29 Time filter has following fields: 30 31 ```yaml 32 filters: 33 time: 34 start: time_range_start_utc 35 stop: time_range_end_utc 36 ``` 37 38 ## How it works 39 40 Time filter takes a `start` and `stop` time in `HH:MM:SS` format in UTC. 41 42 ```yaml 43 apiVersion: argoproj.io/v1alpha1 44 kind: Sensor 45 metadata: 46 name: with-time-filter 47 spec: 48 template: 49 serviceAccountName: operate-workflow-sa 50 dependencies: 51 - name: test-dep 52 eventSourceName: webhook 53 eventName: example 54 filters: 55 time: 56 start: "02:30:00" 57 stop: "04:30:00" 58 ``` 59 60 If `stop` is smaller than `start` (`stop` < `start`), the stop time is treated as next day of `start`. 61 62 **Note**: `start` is inclusive while `stop` is exclusive. 63 64 ### Time filter behaviour visually explained 65 66 1. if `start` < `stop`: event time must be in `[start, stop)`. 67 68 00:00:00 00:00:00 00:00:00 69 ┃ start stop ┃ start stop ┃ 70 ─┸─────●───────────────────────○─────┸─────●───────────────────────○─────┸─ 71 ╰───────── OK ──────────╯ ╰───────── OK ──────────╯ 72 73 1. if `stop` < `start`: event time must be in `[start, stop@Next day)` 74 (this is equivalent to: event time must be in `[00:00:00, stop) || [start, 00:00:00@Next day)`). 75 76 00:00:00 00:00:00 00:00:00 77 ┃ stop start ┃ stop start ┃ 78 ─┸───────────○───────────●───────────┸───────────○───────────●───────────┸─ 79 ─── OK ──────╯ ╰───────── OK ──────────╯ ╰────── OK ─── 80 81 ## Practical example 82 83 1. Create a webhook event-source 84 85 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/event-sources/webhook.yaml 86 87 1. Create a webhook sensor with time filter 88 89 kubectl -n argo-events apply -f https://raw.githubusercontent.com/argoproj/argo-events/stable/examples/sensors/filter-with-time.yaml 90 91 1. Send an HTTP request to event-source 92 93 curl -d '{"message":"this is my first webhook"}' -H "Content-Type: application/json" -X POST http://localhost:12000/example 94 95 1. You will notice one of following behaviours: 96 97 - if you run this example between 02:30 and 04:30, the sensor logs the event is valid 98 - if you run this example outside time range between 02:30 and 04:30, the sensor logs the event is invalid 99 100 ## Further examples 101 102 You can find some examples [here](https://github.com/argoproj/argo-events/tree/master/examples/sensors).