pub struct BiTemporal<T> {
pub data: T,
pub version_id: Uuid,
pub valid_from: NaiveDateTime,
pub valid_to: Option<NaiveDateTime>,
pub recorded_at: DateTime<Utc>,
pub superseded_at: Option<DateTime<Utc>>,
pub recorded_by: String,
pub change_reason: Option<String>,
pub previous_version_id: Option<Uuid>,
pub change_type: TemporalChangeType,
}Expand description
Bi-temporal wrapper for any auditable entity.
Provides two temporal dimensions:
- Business time: When the fact was/is true in the real world
- System time: When the fact was recorded in the system
§Example
use datasynth_core::models::BiTemporal;
// A journal entry that was valid from Jan 1 to Jan 15
// but was recorded on Jan 5 and corrected on Jan 16
let entry = BiTemporal::new(journal_entry)
.with_valid_time(jan_1, Some(jan_15))
.with_recorded_by("user001")
.with_change_reason("Initial posting");Fields§
§data: TThe wrapped data
version_id: UuidUnique version ID for this temporal record
valid_from: NaiveDateTimeWhen this fact became true in the business world
valid_to: Option<NaiveDateTime>When this fact stopped being true (None = still current)
recorded_at: DateTime<Utc>When this record was created in the system
superseded_at: Option<DateTime<Utc>>When this record was superseded by a newer version (None = current version)
recorded_by: StringUser/system that recorded this version
change_reason: Option<String>Reason for change (for corrections/adjustments)
previous_version_id: Option<Uuid>Previous version ID (for version chain)
change_type: TemporalChangeTypeChange type classification
Implementations§
Source§impl<T> BiTemporal<T>
impl<T> BiTemporal<T>
Sourcepub fn with_valid_time(
self,
from: NaiveDateTime,
to: Option<NaiveDateTime>,
) -> Self
pub fn with_valid_time( self, from: NaiveDateTime, to: Option<NaiveDateTime>, ) -> Self
Set the valid time range.
Sourcepub fn valid_from(self, from: NaiveDateTime) -> Self
pub fn valid_from(self, from: NaiveDateTime) -> Self
Set valid_from only.
Sourcepub fn valid_to(self, to: NaiveDateTime) -> Self
pub fn valid_to(self, to: NaiveDateTime) -> Self
Set valid_to only.
Sourcepub fn with_recorded_at(self, recorded_at: DateTime<Utc>) -> Self
pub fn with_recorded_at(self, recorded_at: DateTime<Utc>) -> Self
Set the recorded_at timestamp.
Sourcepub fn with_recorded_by(self, recorded_by: &str) -> Self
pub fn with_recorded_by(self, recorded_by: &str) -> Self
Set who recorded this version.
Sourcepub fn with_change_reason(self, reason: &str) -> Self
pub fn with_change_reason(self, reason: &str) -> Self
Set the change reason.
Sourcepub fn with_change_type(self, change_type: TemporalChangeType) -> Self
pub fn with_change_type(self, change_type: TemporalChangeType) -> Self
Set the change type.
Sourcepub fn with_previous_version(self, previous_id: Uuid) -> Self
pub fn with_previous_version(self, previous_id: Uuid) -> Self
Link to a previous version.
Sourcepub fn is_currently_valid(&self) -> bool
pub fn is_currently_valid(&self) -> bool
Check if this record is currently valid (business time).
Sourcepub fn is_current_version(&self) -> bool
pub fn is_current_version(&self) -> bool
Check if this is the current version (system time).
Sourcepub fn was_valid_at(&self, at: NaiveDateTime) -> bool
pub fn was_valid_at(&self, at: NaiveDateTime) -> bool
Check if this record was valid at a specific business time.
Sourcepub fn was_current_at(&self, at: DateTime<Utc>) -> bool
pub fn was_current_at(&self, at: DateTime<Utc>) -> bool
Check if this version was the current version at a specific system time.
Sourcepub fn supersede(&mut self, superseded_at: DateTime<Utc>)
pub fn supersede(&mut self, superseded_at: DateTime<Utc>)
Supersede this record with a new version.
Sourcepub fn correct(&self, new_data: T, corrected_by: &str, reason: &str) -> Selfwhere
T: Clone,
pub fn correct(&self, new_data: T, corrected_by: &str, reason: &str) -> Selfwhere
T: Clone,
Create a correction of this record.
Sourcepub fn reverse(&self, reversed_by: &str, reason: &str) -> Selfwhere
T: Clone,
pub fn reverse(&self, reversed_by: &str, reason: &str) -> Selfwhere
T: Clone,
Create a reversal of this record.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume and return the underlying data.
Trait Implementations§
Source§impl<T: Clone> Clone for BiTemporal<T>
impl<T: Clone> Clone for BiTemporal<T>
Source§fn clone(&self) -> BiTemporal<T>
fn clone(&self) -> BiTemporal<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more