Skip to main content

adjust_timestamp

Function adjust_timestamp 

Source
pub fn adjust_timestamp(
    datetime: &str,
    adjustment: &str,
    timezone: &str,
) -> Result<AdjustedTimestamp, TruthError>
Expand description

Adjust a timestamp by adding or subtracting a duration.

§Arguments

  • datetime — An RFC 3339 datetime string
  • adjustment — A duration string (e.g., "+2h", "-30m", "+1d2h30m", "+1w")
  • timezone — An IANA timezone name for interpreting day-level adjustments

§Duration Format

Must start with + or -, followed by one or more components:

  • Nw — weeks
  • Nd — days (timezone-aware: same wall-clock time, not +24h across DST)
  • Nh — hours
  • Nm — minutes
  • Ns — seconds

Components can be combined: +1d2h30m, -2w3d.

§Errors

Returns TruthError::InvalidDatetime if the datetime cannot be parsed, TruthError::InvalidTimezone if the timezone is invalid, or TruthError::InvalidDuration if the adjustment string cannot be parsed.