diff options
author | Nora <nora.widdecke@tu-bs.de> | 2019-03-01 17:48:44 +0100 |
---|---|---|
committer | Nora <nora.widdecke@tu-bs.de> | 2019-03-01 17:48:44 +0100 |
commit | 311c66a4b292b548d55bd9334249dab8479bd2dd (patch) | |
tree | a755cd95369a17ec8e87b5de801ef1f16575ce09 /src | |
parent | b2d1176f6d6530804e6757ed20253ad8f375f30a (diff) |
use local timezone config
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/khaleesi.rs | 10 | ||||
-rw-r--r-- | src/config.rs | 28 |
2 files changed, 35 insertions, 3 deletions
diff --git a/src/bin/khaleesi.rs b/src/bin/khaleesi.rs index b1764ac..1d90e15 100644 --- a/src/bin/khaleesi.rs +++ b/src/bin/khaleesi.rs @@ -7,6 +7,8 @@ use khaleesi::KhResult; use structopt::StructOpt; +use std::env; + fn main() { let args = cli::CommandLine::from_args(); @@ -27,6 +29,8 @@ fn main() { let config = Config::read_config(); + init_local_timezone(&config); + let result = main_internal(&args, &config); if let Err(error) = result { error!("{}", error) @@ -74,3 +78,9 @@ fn init_logger(verbose: u64) { // 3 => LevelFilter::Debug, // _ => LevelFilter::Trace, } + +fn init_local_timezone(config: &Config) { + if let Some(local_tz_config) = &config.local_tz { + env::set_var("TZ", &local_tz_config.timezone); + } +} diff --git a/src/config.rs b/src/config.rs index df96b12..083f5d2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,8 @@ use crate::utils::fileutil as utils; #[serde(default)] pub struct Config { pub calendars: HashMap<String,CalendarConfig>, - pub agenda: AgendaConfig + pub agenda: AgendaConfig, + pub local_tz: Option<LocalTZConfig> } #[derive(Deserialize,Debug,PartialEq)] @@ -24,6 +25,11 @@ pub struct CalendarConfig { pub color: Option<u8> } +#[derive(Deserialize,Debug,PartialEq)] +pub struct LocalTZConfig { + pub timezone: String +} + impl Config { pub fn get_config_for_calendar(&self, calendar_name: &str) -> Option<&CalendarConfig> { self.calendars.get(calendar_name) @@ -48,6 +54,12 @@ impl CalendarConfig { } } +impl LocalTZConfig { + pub fn get_local_tz(&self) -> String { + self.timezone.clone() + } +} + impl Default for AgendaConfig { fn default() -> Self { AgendaConfig { @@ -60,8 +72,9 @@ impl Default for AgendaConfig { impl Default for Config { fn default() -> Self { Config { - calendars: HashMap::new(), agenda: AgendaConfig::default(), + calendars: HashMap::new(), + local_tz: None, } } } @@ -92,7 +105,8 @@ mod tests { agenda: AgendaConfig { print_week_separator: true, print_empty_days: false - } + }, + local_tz: None, }; assert_eq!(expected, config); @@ -106,4 +120,12 @@ mod tests { assert_eq!(Color::Fixed(81).style(), style); } + + #[test] + fn test_get_local_tz() { + let config = LocalTZConfig { timezone: "Europe/Berlin".to_string() }; + let tz = config.get_local_tz(); + + assert_eq!("Europe/Berlin".to_string(), tz); + } } |