diff --git a/cove-config/src/lib.rs b/cove-config/src/lib.rs index 4b5e2fe..22fc332 100644 --- a/cove-config/src/lib.rs +++ b/cove-config/src/lib.rs @@ -96,9 +96,8 @@ pub struct Config { /// valid TZ strings: /// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones /// - /// If the option is not specified, cove uses the contents of the `TZ` - /// environment variable instead. If the `TZ` environment variable does not - /// exist, cove uses the system's local time zone. + /// If the `TZ` environment variable exists, it overrides this option. If + /// neither exist, cove uses the system's local time zone. /// /// **Warning:** On Windows, cove can't get the local time zone and uses UTC /// instead. However, you can still specify a path to a tz data file or a diff --git a/cove/src/util.rs b/cove/src/util.rs index 1bc9d6b..6bcbf3e 100644 --- a/cove/src/util.rs +++ b/cove/src/util.rs @@ -18,20 +18,21 @@ impl InfallibleExt for Result { } } -/// Load a [`TimeZone`] specified by a string, or by the `TZ` environment -/// variable if no string is provided. +/// Load a [`TimeZone`] specified by the `TZ` environment varible, or by the +/// provided string if the environment variable does not exist. /// /// If a string is provided, it is interpreted in the same format that the `TZ` /// environment variable uses. /// -/// If no string and no `TZ` environment variable could be found, the system -/// local time is used. +/// If no `TZ` environment variable could be found and no string is provided, +/// the system local time (or UTC on Windows) is used. pub fn load_time_zone(tz_string: Option<&str>) -> Result { - let env_tz = env::var("TZ").ok(); - let tz_string = tz_string.or(env_tz.as_ref().map(|s| s as &str)); + let env_string = env::var("TZ").ok(); + let tz_string = env_string.as_ref().map(|s| s as &str).or(tz_string); match &tz_string { - // At the moment, TimeZone::from_posix_tz does not support "localtime" on windows, but other time zon + // At the moment, TimeZone::from_posix_tz does not support "localtime" + // on Windows, so we handle that case manually. Some("localtime") | None => TimeZone::local(), Some(tz_string) => TimeZone::from_posix_tz(tz_string), }