use super::*;
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct ZdaData {
pub source: NavigationSystem,
#[serde(with = "json_date_time_utc")]
pub timestamp_utc: Option<DateTime<Utc>>,
#[serde(with = "json_fixed_offset")]
pub timezone_local: Option<FixedOffset>,
}
pub(crate) fn handle(
sentence: &str,
nav_system: NavigationSystem,
) -> Result<ParsedMessage, ParseError> {
let split: Vec<&str> = sentence.split(',').collect();
Ok(ParsedMessage::Zda(ZdaData {
source: nav_system,
timestamp_utc: parse_hhmmss_ss(
split.get(1).unwrap_or(&""),
pick_date_with_fields(&split, 4, 3, 2, 0, 0, 0, 0)?,
)
.ok(),
timezone_local: pick_timezone_with_fields(&split, 5, 6).ok(),
}))
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_parse_cpzda() {
match NmeaParser::new().parse_sentence("$GPZDA,072914.00,31,05,2018,-03,00") {
Ok(ps) => match ps {
ParsedMessage::Zda(zda) => {
assert_eq!(zda.source, NavigationSystem::Gps);
assert_eq!(
zda.timestamp_utc,
Utc.with_ymd_and_hms(2018, 5, 31, 7, 29, 14).single()
);
assert_eq!(zda.timezone_local, FixedOffset::east_opt(-3 * 3600));
}
ParsedMessage::Incomplete => {
assert!(false);
}
_ => {
assert!(false);
}
},
Err(e) => {
assert_eq!(e.to_string(), "OK");
}
}
}
}