ModifyDateTime
Takes a date or time input and adds or subtracts a determined amount of time. Returns a string in date or time in ISO Format.
python · Filters And Transformers
Details
| ID | ModifyDateTime |
|---|---|
| Language | python |
| From Version | 5.0.0 |
| Docker Image | demisto/python3:3.12.13.10404775 |
| Tags | transformer date |
README
Takes a date or time input and adds or subtracts a determined amount of time. Returns a string in date or time in ISO Format.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | transformer, date |
| Cortex XSOAR Version | 5.0.0 |
Inputs
| Argument Name | Description |
|---|---|
| value | Input date or time in a format that is supported by the dateparser.parse() function as outlined here- https://dateparser.readthedocs.io/en/latest/#popular-formats. For example: ‘2020-01-01’ or ‘1999/02/03 12:01:59’ |
| variation | Variation of time (for example: ‘in 1 day’, or ‘3 months ago’). Must be supported by the dateparser.parse() function here - https://dateparser.readthedocs.io/en/latest/#relative-dates |
Outputs
There are no outputs for this script.
Script Example
!ModifyDateTime value=2020,02,02 variation="1 day"
Context Example
{}
Human Readable Output
2020-02-01T00:00:00
import dateparser import demistomock as demisto import pytest from ModifyDateTime import apply_variation, main @pytest.mark.parametrize( "original_time, variation, expected", [ # sanity ("2020/01/01", "in 1 day", "2020-01-02T00:00:00"), # textual variation 1 ("2020/01/01", "yesterday", "2019-12-31T00:00:00"), # textual variation 2 ("2020/01/01", "next month", "2020-02-01T00:00:00"), # negative variation ("2020-01-01T01:30:00", "-15m", "2020-01-01T01:15:00"), # positive variation (treated the same as negative according to datetime.parse) ("2020-01-01T01:30:00", "15m", "2020-01-01T01:15:00"), # zulu timezone ("2020-01-01T10:00:00Z", "in 15m", "2020-01-01T10:15:00Z"), # GMT ("2020-01-01T01:30:00+00:00", "15m", "2020-01-01T01:15:00+00:00"), # GMT+ ("2020-01-01T01:30:00+02:00", "15m", "2020-01-01T01:15:00+02:00"), # GMT- ("2020-01-01T01:30:00-04:00", "15m", "2020-01-01T01:15:00-04:00"), ], ) def test_apply_variation(original_time, variation, expected): results = apply_variation(dateparser.parse(original_time), variation) assert results == (dateparser.parse(expected)) @pytest.mark.parametrize( "args", [ {"value": "2020/01/01", "variation": "in 1 day"}, ], ) def test_modify_date_time_main(mocker, args): """ Given: Value and variation. When: Running ModifyDateTime script. Then: demisto.results called. """ mocker.patch.object(demisto, "args", return_value=args) mocker.patch.object(demisto, "results") main() results = demisto.results.call_args[0] assert demisto.results.call_count == 1 assert results[0] == "2020-01-02T00:00:00"