Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 6m9s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
lib.rs is separated into src/modules now for cleaner code optimized error handling to -> (storage.rs, uptime.rs, meta.rs, memory.rs, os.rs, network.rs) optimized struct types to -> (storage.rs, uptime.rs, meta.rs, memory.rs, os.rs, network.rs)
68 lines
1.5 KiB
Rust
68 lines
1.5 KiB
Rust
use chrono::{DateTime, Local, Offset};
|
|
use serde::Serialize;
|
|
use std::{
|
|
cmp::Ordering,
|
|
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
|
ops::Deref,
|
|
};
|
|
|
|
#[derive(Copy, Clone)]
|
|
pub struct FmtOffsetTime(pub DateTime<Local>);
|
|
|
|
impl Display for FmtOffsetTime {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
write!(f, "UTC{}", self.0.offset())
|
|
}
|
|
}
|
|
|
|
impl Debug for FmtOffsetTime {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
|
Display::fmt(self, f)
|
|
}
|
|
}
|
|
|
|
impl Serialize for FmtOffsetTime {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: serde::Serializer,
|
|
{
|
|
serializer.serialize_str(&self.to_string())
|
|
}
|
|
}
|
|
|
|
impl Deref for FmtOffsetTime {
|
|
type Target = DateTime<Local>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl Eq for FmtOffsetTime {}
|
|
impl PartialEq for FmtOffsetTime {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.0.offset().fix() == other.0.offset().fix()
|
|
}
|
|
}
|
|
|
|
impl PartialOrd for FmtOffsetTime {
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
Some(
|
|
self.0
|
|
.offset()
|
|
.fix()
|
|
.local_minus_utc()
|
|
.cmp(&other.0.offset().fix().local_minus_utc()),
|
|
)
|
|
}
|
|
}
|
|
|
|
impl Ord for FmtOffsetTime {
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
|
self.0
|
|
.offset()
|
|
.fix()
|
|
.local_minus_utc()
|
|
.cmp(&other.0.offset().fix().local_minus_utc())
|
|
}
|
|
}
|