Skip to main content

split_custom_interval

Function split_custom_interval 

Source
pub fn split_custom_interval(
    start_datetime: DateTime<Utc>,
    end_datetime: DateTime<Utc>,
    retention_period: &i32,
) -> Result<QueryTimestamps, SqlError>
Expand description

Splits a date range into archived and current table queries based on retention period

§Arguments

  • start_datetime - Start of the query range
  • end_datetime - End of the query range
  • retention_period - Number of days to keep data in current table

§Returns

  • QueryTimestamps containing:
    • archived_range: Some((begin, end)) if query needs archived data
    • archived_minutes: Some(minutes) total minutes in archived range
    • active_range: Some((begin, end)) if query needs current/active data

§Examples

let begin = Utc::now() - Duration::days(60);  // 60 days ago
let end = Utc::now() - Duration::days(1);     // yesterday
let retention = 30;                           // keep 30 days in current table

let result = split_custom_interval(begin, end, &retention)?;
// Will return:
// - archived_range: Some((60 days ago, 30 days ago))
// - archived_minutes: Some(43200) // minutes for 30 days
// - active_range: Some((30 days ago, yesterday))