Time Shift
Synopsis
Shifts timestamps by specified amounts with timezone conversion.
Schema
- timeshift:
field: <ident>
amount: <string>
unit: <string>
target_field: <string>
format: <string>
timezone: <string>
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:
| Field | Required | Default | Description |
|---|---|---|---|
field | Y | - | Source field containing timestamp to shift |
amount | Y | - | Shift amount as numeric string (positive or negative) |
unit | Y | - | Time unit (seconds, minutes, hours, days, weeks, months, years) |
target_field | N | Same as field | Target field to store shifted timestamp |
format | N | RFC3339 | Go time layout for the output. When the source field is a string it also governs parsing, replacing the auto-detected format list — so the stored value must match this layout exactly or the processor fails. It has no effect on parsing when the field is numeric |
timezone | N | - | Target timezone for output |
description | N | - | Explanatory note |
if | N | - | Condition to run |
ignore_failure | N | false | Continue processing if shift fails |
ignore_missing | N | false | Skip processing if referenced field doesn't exist |
on_failure | N | - | See Handling Failures |
on_success | N | - | See Handling Success |
tag | N | - | Identifier |
disabled | N | false | When true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration |
Details
Shifts timestamps by specified amounts supporting various time units and timezone conversions. The processor handles multiple input formats and provides flexible output formatting options.
The processor accepts timestamps as RFC 3339, as Unix timestamps (integer or float, in seconds), and as several common date/time strings. With format unset it tries each known layout in turn, then falls back to reading the value as a Unix timestamp.
format is one setting doing two jobs. For a string field it is the input layout as well as the output layout, so the two cannot differ: format: "2006-01-02" reads 2024-01-15 and writes 2024-04-15, but fails outright on 2024-01-15T00:00:00Z. To reformat a string timestamp into a different layout, shift it here and convert with a separate Date step. A numeric field is unaffected — it is always read as a Unix timestamp, and format shapes only the output.
Time units support both singular and plural forms with common abbreviations: seconds (s, sec, secs), minutes (m, min, mins), hours (h, hr, hrs), days (d), weeks (w), months, and years (y). Fractional amounts are supported for precise time shifts.
For months and years, the processor handles variable lengths carefully. Months use approximate calculations (30.44 days per month) for fractional parts, while years use 365.25 days to account for leap years.
Month and year calculations are approximate for fractional values. For precise date arithmetic, use whole number amounts or convert to days/hours for exact calculations.
Examples
Basic Time Shift
Shifting timestamp forward by 2 hours... | |
adds 2 hours to timestamp: | |
Timezone Conversion with Shift
Shifting time and converting timezone... | |
shifts to previous day in EST: | |
Unix Timestamp Processing
Processing Unix timestamp with custom format... | |
formats shifted time as readable string: | |
Negative Time Shift
Shifting timestamp backward for log correlation... | |
creates earlier timestamp for correlation: | |
Fractional Time Units
Using fractional hours for precise shifts... | |
shifts by 1.5 hours, writing RFC 3339: | |
Monthly Scheduling
Calculating monthly report dates... | |
the same layout reads the input and writes the result: | |
Week-based Scheduling
Calculating weekly maintenance windows... | |
schedules next maintenance in local time: | |
String Date Processing
Processing various string date formats... | |
parses and shifts with readable output: | |