fix: Add macOS support for time sync command

Co-authored-by: aider (gemini/gemini-2.5-pro-preview-05-06) <aider@aider.chat>
This commit is contained in:
Chaos Rogers 2025-07-21 18:39:48 +01:00
parent ac08ffb54f
commit 0a9f9c6612

View file

@ -71,8 +71,9 @@ pub fn trigger_sync(frame: &LtcFrame) -> Result<String, ()> {
.from_local_datetime(&naive_dt) .from_local_datetime(&naive_dt)
.single() .single()
.expect("Ambiguous or invalid local time"); .expect("Ambiguous or invalid local time");
#[cfg(target_os = "linux")]
let (ts, success) = {
let ts = dt_local.format("%H:%M:%S.%3f").to_string(); let ts = dt_local.format("%H:%M:%S.%3f").to_string();
let success = Command::new("sudo") let success = Command::new("sudo")
.arg("date") .arg("date")
.arg("-s") .arg("-s")
@ -80,6 +81,29 @@ pub fn trigger_sync(frame: &LtcFrame) -> Result<String, ()> {
.status() .status()
.map(|s| s.success()) .map(|s| s.success())
.unwrap_or(false); .unwrap_or(false);
(ts, success)
};
#[cfg(target_os = "macos")]
let (ts, success) = {
// macOS `date` command format is `mmddHHMMccyy.SS`
let ts = dt_local.format("%m%d%H%M%y.%S").to_string();
let success = Command::new("sudo")
.arg("date")
.arg(&ts)
.status()
.map(|s| s.success())
.unwrap_or(false);
(ts, success)
};
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let (ts, success) = {
// Unsupported OS, always fail
let ts = dt_local.format("%H:%M:%S.%3f").to_string();
eprintln!("Unsupported OS for time synchronization");
(ts, false)
};
if success { if success {
Ok(ts) Ok(ts)