BetweenHours
Checks whether the given value is within the specified time (hour) range.
- Type
- python
- Pack
- FiltersAndTransformers
Source
import dateparser
import demistomock as demisto # noqa: F401
from CommonServerPython import * # noqa: F401
def is_between_hours(value, begin_time, end_time):
# https://stackoverflow.com/questions/71256416/pytzusagewarning-doesnt-seem-to-go-away
input_time = dateparser.parse(value, settings={"TIMEZONE": "UTC"}).time() # type: ignore
start_time = dateparser.parse(begin_time, settings={"TIMEZONE": "UTC"}).time() # type: ignore
end_time = dateparser.parse(end_time, settings={"TIMEZONE": "UTC"}).time() # type: ignore
if start_time >= end_time: # if the time range crosses midnight.
return start_time <= input_time or input_time <= end_time
return start_time <= input_time <= end_time
if __name__ in ("__main__", "__builtin__", "builtins"):
args = demisto.args()
value, begin_time, end_time = args["value"], args["begin_time"], args["end_time"]
result = is_between_hours(value, begin_time, end_time)
output = {"value": value, "begin_time": begin_time, "end_time": end_time, "result": result}
human_readable = (
f'# BetweenHours\nThe time *{value}* {"*IS*" if result else "*IS NOT*"} between *{begin_time}* and *{end_time}*'
)
return_results(CommandResults(outputs_prefix="BetweenHours", readable_output=human_readable, outputs=result))
README
Checks whether the given value is within the specified time (hour) range.
Script Data
| Name |
Description |
| Script Type |
python3 |
| Tags |
transformer, date |
| Cortex XSOAR Version |
5.0.0 |
Inputs
| Argument Name |
Description |
| value |
The value to check. |
| begin_time |
The start time range in the format HH:MM:SS. |
| end_time |
The end time range in the format HH:MM:SS. |
Outputs
| Path |
Description |
Type |
| BetweenHours.result |
Whether the input hour is between the given hours. |
boolean |
| BetweenHours.value |
The value to check. |
string |
| BetweenHours.begin_time |
The start time range in the format HH:MM:SS. |
string |
| BetweenHours.end_time |
The end time range in the format HH:MM:SS. |
string |