holodeck_simctl_core/
default_media_path.rs1use std::path::{Path, PathBuf};
2
3use chrono::{DateTime, Local};
4
5use crate::models::ScreenshotType;
6
7fn timestamp(date: DateTime<Local>) -> String {
8 date.format("%Y%m%d-%H%M%S").to_string()
9}
10
11pub fn record(directory: &Path, date: DateTime<Local>) -> PathBuf {
12 directory.join(format!("sim_record_{}.mp4", timestamp(date)))
13}
14
15pub fn screenshot(directory: &Path, screenshot_type: ScreenshotType, date: DateTime<Local>) -> PathBuf {
16 directory.join(format!("sim_screenshot_{}.{}", timestamp(date), screenshot_type.raw_value()))
17}
18
19pub fn ensure_directory_exists(path: &Path) -> std::io::Result<()> {
20 if let Some(parent) = path.parent() {
21 std::fs::create_dir_all(parent)?;
22 }
23 Ok(())
24}
25
26#[cfg(test)]
27mod tests {
28 use super::*;
29 use chrono::TimeZone;
30
31 fn fixed_date() -> DateTime<Local> {
32 Local.with_ymd_and_hms(2026, 5, 13, 12, 19, 4).unwrap()
33 }
34
35 #[test]
36 fn record_path_has_expected_format() {
37 let path = record(Path::new("/tmp"), fixed_date());
38 assert_eq!(path, PathBuf::from("/tmp/sim_record_20260513-121904.mp4"));
39 }
40
41 #[test]
42 fn screenshot_path_uses_extension_from_type() {
43 let path = screenshot(Path::new("/tmp"), ScreenshotType::Jpeg, fixed_date());
44 assert_eq!(path, PathBuf::from("/tmp/sim_screenshot_20260513-121904.jpeg"));
45 }
46}