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>,
|
start_time: &mut Option<NaiveDateTime>,
|
||||||
subjects: &mut SubjectMap<Self::PerSubjectData>,
|
subjects: &mut SubjectMap<Self::PerSubjectData>,
|
||||||
) -> Result<(), Error> {
|
) -> 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 {
|
let match_time = match start_time {
|
||||||
Some(start_time) => (event_time - *start_time).num_seconds() as u32,
|
Some(start_time) => (event_time - *start_time).num_seconds() as u32,
|
||||||
None => {
|
None => {
|
||||||
|
|
|
||||||
|
|
@ -51,16 +51,20 @@ impl<'a> TryFrom<RawDate<'a>> for NaiveDateTime {
|
||||||
type Error = ParseIntError;
|
type Error = ParseIntError;
|
||||||
|
|
||||||
fn try_from(RawDate(raw): RawDate<'a>) -> Result<Self, Self::Error> {
|
fn try_from(RawDate(raw): RawDate<'a>) -> Result<Self, Self::Error> {
|
||||||
Ok(
|
let month = raw[0..2].parse()?;
|
||||||
NaiveDate::from_ymd_opt(raw[6..10].parse()?, raw[0..2].parse()?, raw[3..5].parse()?)
|
let day = raw[3..5].parse()?;
|
||||||
.unwrap()
|
let year = raw[6..10].parse()?;
|
||||||
.and_hms_opt(
|
|
||||||
raw[13..15].parse()?,
|
// one out of the 3.5 million+ logs, 1 randomly has DD/MM/YYYY instead of MM/DD/YYYY?
|
||||||
raw[16..18].parse()?,
|
|
||||||
raw[19..21].parse()?,
|
Ok(NaiveDate::from_ymd_opt(year, month, day)
|
||||||
)
|
.ok_or_else(|| "257".parse::<u8>().unwrap_err())?
|
||||||
.unwrap(),
|
.and_hms_opt(
|
||||||
)
|
raw[13..15].parse()?,
|
||||||
|
raw[16..18].parse()?,
|
||||||
|
raw[19..21].parse()?,
|
||||||
|
)
|
||||||
|
.unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue