feat: automatic dates; timezone setting support
This commit is contained in:
parent
a9dda39526
commit
36542ea0b9
6 changed files with 593 additions and 147 deletions
|
|
@ -1,14 +0,0 @@
|
|||
[package]
|
||||
name = "cosmic-settings-time"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
icu_calendar = "1.5.2"
|
||||
icu_timezone = "1.5.0"
|
||||
timedate-zbus = "0.1.0"
|
||||
|
||||
[dependencies.zbus]
|
||||
version = "3.15.2"
|
||||
default-features = false
|
||||
features = ["tokio"]
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Copyright 2023 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::time::SystemTime;
|
||||
|
||||
use icu_calendar::{types::IsoSecond, DateTime, Iso};
|
||||
use icu_timezone::CustomTimeZone;
|
||||
use timedate_zbus::TimeDateProxy;
|
||||
|
||||
pub struct Info {
|
||||
pub can_ntp: bool,
|
||||
pub timezone: CustomTimeZone,
|
||||
pub local_time: DateTime<Iso>,
|
||||
}
|
||||
|
||||
impl Info {
|
||||
pub async fn load(proxy: &TimeDateProxy<'_>) -> Option<Info> {
|
||||
let can_ntp = proxy.can_ntp().await.unwrap_or_default();
|
||||
|
||||
let Ok(timezone) = proxy
|
||||
.timezone()
|
||||
.await
|
||||
.unwrap_or_default()
|
||||
.parse::<CustomTimeZone>()
|
||||
else {
|
||||
return None;
|
||||
};
|
||||
|
||||
let Ok(duration) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) else {
|
||||
return None;
|
||||
};
|
||||
|
||||
let seconds = duration.as_secs();
|
||||
|
||||
let Ok(iso_seconds) = IsoSecond::try_from((seconds % 60) as u8) else {
|
||||
return None;
|
||||
};
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
let mut local_time = DateTime::from_minutes_since_local_unix_epoch((seconds / 60) as i32);
|
||||
|
||||
local_time.time.second = iso_seconds;
|
||||
|
||||
Some(Info {
|
||||
can_ntp,
|
||||
timezone,
|
||||
local_time,
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue