BetweenHours

Checks whether the given value is within the specified time (hour) range.

python · Filters And Transformers

Details

IDBetweenHours
Languagepython
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10404775
Tagstransformer date

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
import pytest
from BetweenHours import is_between_hours

TEST_INPUTS = [
    ("12:00:00", "02:00:00", "21:00:00", True, "sanity 1"),
    ("12:00:00", "11:10:00", "12:50:00", True, "sanity 3"),
    ("12:00:00", "12:00:00", "12:00:00", True, "exact same date"),
    ("12:00:00", "12:00:00", "22:00:00", True, "same as begin date"),
    ("12:00:00", "10:00:00", "12:00:00", True, "same as end date"),
    ("10:00:00", "12:00:00", "20:00:00", False, "before begin date"),
    ("15:00:00", "02:00:00", "12:00:00", False, "after end date"),
    ("23:00:00", "22:00:00", "02:00:00", True, "between midnight 1"),
    ("01:00:00", "20:00:00", "05:00:00", True, "between midnight 2"),
    ("17:00:00", "22:00:00", "02:00:00", False, "before midnight"),
    ("06:00:00", "20:00:00", "05:00:00", False, "after midnight"),
]


@pytest.mark.parametrize("value, begin_time, end_time, expected_result, test_title", TEST_INPUTS)
def test_is_between_hours(value, begin_time, end_time, expected_result, test_title):
    assert is_between_hours(value, begin_time, end_time) == expected_result, test_title