Skip to content

Commit

Permalink
Allow unused warning in UnixTimestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Apr 14, 2024
1 parent e85adf4 commit e76cd2e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/private/utils/unix_timestamp.rs
Expand Up @@ -18,10 +18,7 @@ enum ErrorKind {
pub(crate) struct UnixTimestamp(i64);

impl UnixTimestamp {
pub(crate) fn now() -> Self {
Self::from_system_time(SystemTime::now()).expect("now to be valid")
}

#[allow(unused)]
pub(crate) fn from_iso8601_basic_format_date_time(s: &str) -> Result<Self, Error> {
let chrono_date_time = chrono::NaiveDateTime::parse_from_str(s, "%Y%m%dT%H%M%SZ")
.map_err(|_| ErrorKind::InvalidIso8601Format(s.to_string()))?
Expand Down Expand Up @@ -56,21 +53,22 @@ impl UnixTimestamp {
year * 10000 + month * 100 + day
}

pub(crate) fn to_iso8601_basic_format_date_time(self) -> String {
let chrono_date_time =
chrono::DateTime::from_timestamp(self.0, 0_u32).expect("self.0 to be valid timestamp");
chrono_date_time.format("%Y%m%dT%H%M%SZ").to_string()
}

pub(crate) fn to_rfc3339(self) -> String {
let chrono_date_time =
chrono::DateTime::from_timestamp(self.0, 0_u32).expect("self.0 to be valid timestamp");
chrono_date_time.format("%Y-%m-%dT%H:%M:%SZ").to_string()
}

#[allow(unused)]
pub(crate) fn to_system_time(self) -> SystemTime {
SystemTime::UNIX_EPOCH + std::time::Duration::from_secs(self.0 as u64)
}

pub(crate) fn to_iso8601_basic_format_date_time(self) -> String {
let chrono_date_time =
chrono::DateTime::from_timestamp(self.0, 0_u32).expect("self.0 to be valid timestamp");
chrono_date_time.format("%Y%m%dT%H%M%SZ").to_string()
}
}

impl std::convert::From<UnixTimestamp> for i64 {
Expand Down

0 comments on commit e76cd2e

Please sign in to comment.