mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-11-30 12:50:49 +01:00
don't panic on invalid dates
This commit is contained in:
parent
626dedd73b
commit
9ab5d1903f
2 changed files with 15 additions and 11 deletions
|
|
@ -36,7 +36,7 @@ pub trait EventHandler: Default {
|
|||
start_time: &mut Option<NaiveDateTime>,
|
||||
subjects: &mut SubjectMap<Self::PerSubjectData>,
|
||||
) -> Result<(), Error> {
|
||||
let event_time: NaiveDateTime = raw_event.date.try_into().unwrap();
|
||||
let event_time: NaiveDateTime = raw_event.date.try_into()?;
|
||||
let match_time = match start_time {
|
||||
Some(start_time) => (event_time - *start_time).num_seconds() as u32,
|
||||
None => {
|
||||
|
|
|
|||
|
|
@ -51,16 +51,20 @@ impl<'a> TryFrom<RawDate<'a>> for NaiveDateTime {
|
|||
type Error = ParseIntError;
|
||||
|
||||
fn try_from(RawDate(raw): RawDate<'a>) -> Result<Self, Self::Error> {
|
||||
Ok(
|
||||
NaiveDate::from_ymd_opt(raw[6..10].parse()?, raw[0..2].parse()?, raw[3..5].parse()?)
|
||||
.unwrap()
|
||||
let month = raw[0..2].parse()?;
|
||||
let day = raw[3..5].parse()?;
|
||||
let year = raw[6..10].parse()?;
|
||||
|
||||
// one out of the 3.5 million+ logs, 1 randomly has DD/MM/YYYY instead of MM/DD/YYYY?
|
||||
|
||||
Ok(NaiveDate::from_ymd_opt(year, month, day)
|
||||
.ok_or_else(|| "257".parse::<u8>().unwrap_err())?
|
||||
.and_hms_opt(
|
||||
raw[13..15].parse()?,
|
||||
raw[16..18].parse()?,
|
||||
raw[19..21].parse()?,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue