Skip to main content
Version: 1.4.0

Duration

Date and Time

Synopsis

Converts time duration strings to seconds.

Schema

- duration:
field: <ident>
target_field: <ident>
description: <text>
if: <script>
ignore_failure: <boolean>
ignore_missing: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
fieldY-Source field containing the duration string
target_fieldNvalue of fieldDestination field to store the converted duration in seconds
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if conversion fails
ignore_missingNfalseSkip if source field doesn't exist
on_failureN-Error handling processors
on_successN-Success handling processors
tagN-Identifier

Supported Formats

The processor can handle the following duration formats:

  1. Go Duration Format:

    • "5s" (5 seconds)
    • "1m30s" (1 minute and 30 seconds)
    • "2h45m" (2 hours and 45 minutes)
    • "24h" (24 hours)
  2. Time Format:

    • "HH:MM:SS" (hours:minutes:seconds)
    • "MM:SS" (minutes:seconds)

Description

Converts a string representing a time duration into a numeric value in seconds. The processor supports multiple duration formats including Go's duration syntax (e.g., "5m", "2h30m") and time notation formats (e.g., "HH:MM:SS", "MM:SS").

note

When using the time format (HH:MM:SS), the processor assumes that the values represent hours, minutes, and seconds respectively. For MM:SS format, the processor assumes minutes and seconds.

The processor is useful for normalizing various time duration notations into a consistent numeric format that can be used for calculations, filtering, or visualization.

warning

Invalid duration formats will cause the processor to fail unless ignore_failure is set to true. Always validate input data or provide proper error handling when processing user-generated duration strings.

Examples

Basic

Go duration format...

{
"event": {
"duration_str": "5m30s"
}
}
- duration:
field: event.duration_str
target_field: event.duration_seconds

is converted to seconds:

{
"event": {
"duration_str": "5m30s",
"duration_seconds": 330
}
}

Time Format

Converting time notation...

{
"video": {
"length": "1:45:30"
}
}
- duration:
field: video.length
target_field: video.length_seconds

parses hours, minutes, and seconds:

{
"video": {
"length": "1:45:30",
"length_seconds": 6330
}
}

In-Place

Replacing the original field...

{
"task": {
"elapsed_time": "45:20"
}
}
- duration:
field: task.elapsed_time

converts the value in place:

{
"task": {
"elapsed_time": 2720
}
}

Error Handling

Handling potential parsing errors...

{
"log": {
"duration": "invalid"
}
}
- duration:
field: log.duration
target_field: log.duration_seconds
ignore_failure: true
on_failure:
- set:
field: log.error
value: "Failed to parse duration"

continues execution:

{
"log": {
"duration": "invalid",
"error": "Failed to parse duration"
}
}