diff options
author | Jesse Luehrs <doy@tozt.net> | 2022-01-05 07:18:29 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2022-01-05 07:18:29 -0500 |
commit | a30174620d6b64f838989a634c265a353b2ab117 (patch) | |
tree | 023ff89d0a7b61550b17eb49702722c81c38499c /src/info.rs | |
parent | 404ae6202e24c7bfc5625edb3ac064df4ecd105f (diff) | |
download | nbsh-a30174620d6b64f838989a634c265a353b2ab117.tar.gz nbsh-a30174620d6b64f838989a634c265a353b2ab117.zip |
a bunch more reorganization
Diffstat (limited to 'src/info.rs')
-rw-r--r-- | src/info.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/info.rs b/src/info.rs index 5653326..e441b16 100644 --- a/src/info.rs +++ b/src/info.rs @@ -28,3 +28,23 @@ pub fn time(offset: time::UtcOffset) -> anyhow::Result<String> { time::OffsetDateTime::now_utc().to_offset(offset), )) } + +// the time crate is currently unable to get the local offset on unix due to +// soundness concerns, so we have to do it manually/: +// +// https://github.com/time-rs/time/issues/380 +pub fn get_offset() -> time::UtcOffset { + let offset_str = + std::process::Command::new("date").args(&["+%:z"]).output(); + if let Ok(offset_str) = offset_str { + let offset_str = String::from_utf8(offset_str.stdout).unwrap(); + time::UtcOffset::parse( + offset_str.trim(), + &time::format_description::parse("[offset_hour]:[offset_minute]") + .unwrap(), + ) + .unwrap_or(time::UtcOffset::UTC) + } else { + time::UtcOffset::UTC + } +} |