Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 71 additions & 1 deletion src-tauri/src/intune/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,11 @@ pub fn parse_timestamp(value: &str) -> Option<NaiveDateTime> {
}
}

None
// RFC 3339 / ISO 8601 with timezone (e.g. "2024-01-15T10:30:00.000Z")
// IME parser produces timestamp_utc in this format via to_rfc3339_opts().
chrono::DateTime::parse_from_rfc3339(value)
.map(|dt| dt.naive_utc())
.ok()
}

pub fn calculate_timestamp_bounds(events: &[IntuneEvent]) -> Option<IntuneTimestampBounds> {
Expand Down Expand Up @@ -303,6 +307,7 @@ fn format_duration(total_secs: f64) -> String {
#[cfg(test)]
mod tests {
use super::*;
use chrono::Timelike;

#[test]
fn test_format_duration() {
Expand Down Expand Up @@ -544,6 +549,71 @@ mod tests {
assert!(untimed.end_time_epoch.is_none());
}

#[test]
fn parse_timestamp_handles_rfc3339() {
let result = parse_timestamp("2024-01-15T10:30:00.000Z");
assert!(result.is_some());
let dt = result.unwrap();
assert_eq!(dt.hour(), 10);
assert_eq!(dt.minute(), 30);
}

#[test]
fn parse_timestamp_handles_rfc3339_with_offset() {
let result = parse_timestamp("2024-01-15T10:30:00.000+05:00");
assert!(result.is_some());
let dt = result.unwrap();
// naive_utc converts to UTC: 10:30 +05:00 = 05:30 UTC
assert_eq!(dt.hour(), 5);
assert_eq!(dt.minute(), 30);
}

#[test]
fn build_timeline_sorts_rfc3339_timestamps_across_files() {
let timeline = build_timeline(vec![
IntuneEvent {
id: 0,
event_type: IntuneEventType::Win32App,
name: "Later".to_string(),
guid: None,
status: IntuneStatus::InProgress,
start_time: Some("2024-12-31T10:00:00.000Z".to_string()),
end_time: None,
duration_secs: None,
error_code: None,
detail: "later".to_string(),
source_file: "b.log".to_string(),
line_number: 2,
start_time_epoch: None,
end_time_epoch: None,
},
IntuneEvent {
id: 1,
event_type: IntuneEventType::Win32App,
name: "Earlier".to_string(),
guid: None,
status: IntuneStatus::InProgress,
start_time: Some("2024-01-01T10:00:00.000Z".to_string()),
end_time: None,
duration_secs: None,
error_code: None,
detail: "earlier".to_string(),
source_file: "a.log".to_string(),
line_number: 1,
start_time_epoch: None,
end_time_epoch: None,
},
]);

// Events should be interleaved by time, not grouped by file
assert_eq!(timeline[0].name, "Earlier");
assert_eq!(timeline[0].source_file, "a.log");
assert_eq!(timeline[1].name, "Later");
assert_eq!(timeline[1].source_file, "b.log");
assert!(timeline[0].start_time_epoch.is_some());
assert!(timeline[1].start_time_epoch.is_some());
}

#[test]
fn build_timeline_reassigns_ids_after_sorting() {
let timeline = build_timeline(vec![
Expand Down
Loading