Skip to content

Commit

Permalink
Fix disruptions
Browse files Browse the repository at this point in the history
- Better ? vs & detection for queries
- Allow service_time to deser to None for an empty string.
- Properly use QUIET env
  • Loading branch information
tascord committed Apr 9, 2024
1 parent e082dfc commit 7dd18b4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ where
{
let s: Option<String> = Option::deserialize(deserializer)?;
match s {
Some(s) => Ok(Some(
NaiveDateTime::parse_from_str(&s, "%H:%M:%S").map_err(|e| {
serde::de::Error::custom(format!("Error deser service_time '{s}': {e:?}"))
})?,
)),
Some(s) => {
if s.is_empty() {
Ok(None)
} else {
Ok(Some(
NaiveDateTime::parse_from_str(&s, "%H:%M:%S").map_err(|e| {
serde::de::Error::custom(format!("Error deser service_time '{s}': {e:?}"))
})?,
))
}
}
None => Ok(None),
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ impl Client {
let path = format!(
"/{path}{}devid={}",
{
if path.ends_with('?') {
""
if !path.contains('?') {
"?"
} else {
"&"
if path.ends_with('?') {
""
} else {
"&"
}
}
},
self.devid
Expand Down
2 changes: 2 additions & 0 deletions src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,8 @@ pub struct DisruptionDirection {
#[serde(rename = "direction_name")]
pub name: String,
/// Time of service to which disruption applies. Returns None if disruption applies to multiple, or no services
///
/// This doesn't use null, it uses a blank string. I hate it here.
#[serde(deserialize_with = "de_service_time")]
pub service_time: Option<NaiveDateTime>,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub mod test {
"passed".green(),
elapsed,
{
if std::env::var("quiet").is_ok() {
if std::env::var("QUIET").is_err() {
format!("\n{}", res.cyan())
} else {
" ...".cyan().to_string()
Expand Down

0 comments on commit 7dd18b4

Please sign in to comment.