TimeComponents
This Script is part of the Filters And Transformers Pack.#
Supported versions
Supported Cortex XSOAR versions: 6.5.0 and later.
Takes a date or time input and get time components in a specific time zone. Returns a dictionary with the following components.
- year
- year_4_digit
- month
- month_3_letter
- month_full_name
- month_2_digit
- day
- day_2_digit
- day_of_week (Sun:0, Sat:6)
- day_of_week_3_letter
- day_of_week_full_name
- day_of_year
- day_of_year_3_digit
- hour
- hour_12_clock
- hour_2_digit_24_clock
- hour_2_digit_12_clock
- hour_of_day
- minute
- minute_2_digit
- minute_of_day
- second
- second_2_digit
- second_of_day
- millisecond
- period_12_clock
- time_zone_hhmm
- time_zone_offset
- time_zone_abbreviations
- unix_epoch_time
- iso_8601
- y-m-d
- yyyy-mm-dd
- hⓂ️s
- HⓂ️s
- hh:mm:ss
- HH:mm:ss
Script Data#
| Name | Description |
|---|---|
| Script Type | python3 |
| Tags | transformer, date |
| Cortex XSOAR Version | 6.5.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'. (Default is the current time). Assume given time is in UTC if time zone is not detected. |
| time_zone | The time zone (e.g. -0400, +09:00) or time string to extract a time zone |
| key | The name of a key to choose which time component to return |
Outputs#
There are no outputs for this script.
Examples#
Get all the time components from the time taken#
Parameters#
| Argument Name | Value |
|---|---|
| value | 2022-01-23 01:23:45 +00:00 |
| time_zone | |
| key |
Output#
Get all the time components in a specific time zone#
Parameters#
| Argument Name | Value |
|---|---|
| value | 2022-01-23 01:23:45 +00:00 |
| time_zone | +09:00 |
| key |
Output#
Get all the time components from the unix timestamp#
Parameters#
| Argument Name | Value |
|---|---|
| value | 1642868625 |
| time_zone | |
| key |
Output#
Get a specific time component (day_of_week_full_name)#
Parameters#
| Argument Name | Value |
|---|---|
| value | 2022-01-23 01:23:45 +00:00 |
| time_zone | |
| key | day_of_week_full_name |
Output#
Get a time component in a specific time zone given by zone info#
Parameters#
| Argument Name | Value |
|---|---|
| value | 2022-01-23 01:23:45 +00:00 |
| time_zone | Asia/Tokyo |
| key | iso_8601 |
Output#
Get a time component in a time zone which is extracted from the time string given to time_zone#
Parameters#
| Argument Name | Value |
|---|---|
| value | 2022-01-23 01:23:45 +00:00 |
| time_zone | 2022-01-01 00:00:00 +09:00 |
| key | iso_8601 |
Output#
Get a current time in a specific time zone#
Parameters#
| Argument Name | Value |
|---|---|
| value | now |
| time_zone | +09:00 |
| key | iso_8601 |
Output#
Tips#
Build a custom time format string#
You can create a custom time format in combination with the DT transformer on the chain of transformers. For example, now you want to create a RFC 1123 date string such as Thu, 10 Nov 2022 08:01:44 +0200, and have the following results from the TimeComponents.
Table 1
You can set the following value to the dt parameter of the DT transformer to build the RFC 1123 date string you want.
Parameters to DT#
| Argument Name | Value |
|---|---|
| value | <Table 1> |
| dt | .=val.day_of_week_3_letter + ", " + val.day + " " + val.month_3_letter + " " + val.year + " " + val["HH:mm:ss"] + " " + val.time_zone_hhmm |