summaryrefslogtreecommitdiff
path: root/src/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/time.rs')
-rw-r--r--src/time.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/time.rs b/src/time.rs
index 98256b1..a9f3502 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -1,4 +1,3 @@
-use crate::error::RikiError;
use log::trace;
use std::time::{Duration, SystemTime};
use time::{
@@ -9,7 +8,13 @@ use time::{
OffsetDateTime, PrimitiveDateTime,
};
-pub fn parse_timestamp(timestamp: &str) -> Result<SystemTime, RikiError> {
+#[derive(Debug, thiserror::Error)]
+pub enum TimeError {
+ #[error("failed to parse date: {0:?}")]
+ UnknownTimestamp(String),
+}
+
+pub fn parse_timestamp(timestamp: &str) -> Result<SystemTime, TimeError> {
trace!("parsing timestamp {:?}", timestamp);
let odt = parse(timestamp)?;
let unix = odt.unix_timestamp();
@@ -24,7 +29,7 @@ fn system_time(unix: i64) -> SystemTime {
SystemTime::UNIX_EPOCH.checked_add(offset).unwrap()
}
-fn parse(timestamp: &str) -> Result<OffsetDateTime, RikiError> {
+fn parse(timestamp: &str) -> Result<OffsetDateTime, TimeError> {
const SIMPLIFIED_ISO9601: &[FormatItem<'static>] =
format_description!("[year]-[month]-[day] [hour]:[minute]:[second]");
const SIMPLIFIED_ISO9601_MIN: &[FormatItem<'static>] =
@@ -51,7 +56,7 @@ fn parse(timestamp: &str) -> Result<OffsetDateTime, RikiError> {
} else if let Ok(t) = parse_one_time_format(timestamp, "RFC2822", &Rfc2822) {
Ok(t)
} else {
- Err(RikiError::UnknownTimestamp(timestamp.into()))
+ Err(TimeError::UnknownTimestamp(timestamp.into()))
}
}