Skip to main content

Module temporal

Module temporal 

Source
Expand description

Bitemporal types for knowledge graph time tracking.

This module provides types for implementing bitemporal data models, enabling queries like “what did we know at time T?” and “when was this fact true?”

§Bitemporal Concepts

Bitemporal data tracking uses two independent time dimensions:

DimensionQuestion AnsweredExample
Valid TimeWhen was this fact true in the real world?“Alice worked at Acme from 2020-2023”
Transaction TimeWhen was this fact recorded in the system?“We learned this on 2024-01-15”

§Valid Time Semantics

Valid time represents when a fact was/is/will be true in the real world:

  • ValidTimeRange::unbounded() - Always true (default for most entities)
  • ValidTimeRange::from(start) - True from start onwards
  • ValidTimeRange::until(end) - True until end
  • ValidTimeRange::between(start, end) - True during the interval

§Transaction Time Semantics

Transaction time is automatically set when a record is created and never modified. This enables auditing and point-in-time queries (“what did the system know at time T?”).

§Example

use subcog::models::temporal::{ValidTimeRange, TransactionTime};

// Entity was valid from Jan 1, 2024 onwards
let valid_time = ValidTimeRange::from(1704067200);

// Check if valid at a specific point
assert!(valid_time.contains(1704153600)); // Jan 2, 2024
assert!(!valid_time.contains(1703980800)); // Dec 31, 2023

// Transaction time is auto-set to now
let tx_time = TransactionTime::now();
assert!(tx_time.timestamp() > 0);

Structs§

BitemporalPoint
A bitemporal point representing both valid and transaction time.
TransactionTime
Represents when a fact was recorded in the system (transaction time).
ValidTimeRange
Represents when a fact was true in the real world (valid time).

Functions§

current_timestamp
Returns the current Unix timestamp in seconds.