use std::process::Command;

use super::cmd_stdout;

pub fn ntp_enabled() -> bool
{
	cmd_stdout( "timedatectl", &[ "show", "-p", "NTP", "--value" ] ).trim() == "yes"
}

pub fn set_ntp( on: bool ) -> bool
{
	Command::new( "timedatectl" )
		.args( [ "set-ntp", if on { "true" } else { "false" } ] )
		.status().map( |s| s.success() ).unwrap_or( false )
}

/// `when` is "YYYY-MM-DD HH:MM:SS"; systemd rejects it while NTP is active.
pub fn set_datetime( when: &str ) -> bool
{
	Command::new( "timedatectl" )
		.args( [ "set-time", when ] )
		.status().map( |s| s.success() ).unwrap_or( false )
}
