Skip to content

Commit

Permalink
fix(parser): Valid datetime parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
whydouneedmynick committed Jun 26, 2024
1 parent 1e3c915 commit 5ad1ee8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 170 deletions.
198 changes: 41 additions & 157 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition = "2021"

[dependencies]
anyhow = "1.0.81"
chrono = "0.4.38"
clap = { version = "4.5.6", features = ["derive"] }
env_logger = "0.11.3"
flate2 = "1.0.28"
log = "0.4.21"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
time = { version = "0.3.36", features = ["serde", "parsing", "formatting", "macros"] }

31 changes: 19 additions & 12 deletions src/log_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::Serialize;
use serde_json::Value;
use std::error::Error;
use std::fmt;
use time::OffsetDateTime;

// Define a custom error type
#[derive(Debug)]
Expand Down Expand Up @@ -107,8 +108,10 @@ pub struct IDECommandLineBuildLog {
pub domain_type: String,
pub title: String,
pub signature: String,
pub time_started_recording: f64,
pub time_stopped_recording: f64,
#[serde(with = "time::serde::iso8601")]
pub time_started_recording: OffsetDateTime,
#[serde(with = "time::serde::iso8601")]
pub time_stopped_recording: OffsetDateTime,
pub sub_sections: Vec<IDEActivityLogSection>,
}

Expand All @@ -129,8 +132,8 @@ where
let domain_type = String::try_from(read_token!(tokens)?)?;
let title = String::try_from(read_token!(tokens)?)?;
let signature = String::try_from(read_token!(tokens)?)?;
let time_started_recording = f64::try_from(read_token!(tokens)?)?;
let time_stopped_recording = f64::try_from(read_token!(tokens)?)?;
let time_started_recording = OffsetDateTime::try_from(read_token!(tokens)?)?;
let time_stopped_recording = OffsetDateTime::try_from(read_token!(tokens)?)?;
let sub_sections_size = Option::<usize>::try_from(read_token!(tokens)?)?.unwrap_or(0);
let sub_sections = deser_vec(tokens, sub_sections_size, class_position_to_name);
log::info!(
Expand Down Expand Up @@ -172,8 +175,10 @@ pub struct IDEActivityLogSection {
pub domain_type: String,
pub title: String,
pub signature: String,
pub time_started_recording: f64,
pub time_stopped_recording: f64,
#[serde(with = "time::serde::iso8601")]
pub time_started_recording: OffsetDateTime,
#[serde(with = "time::serde::iso8601")]
pub time_stopped_recording: OffsetDateTime,
pub sub_sections: Vec<IDEActivityLogSection>,
pub text: Option<String>,
pub messages: Vec<IDEActivityLogMessage>,
Expand Down Expand Up @@ -208,8 +213,8 @@ where
let domain_type = String::try_from(read_token!(tokens)?)?;
let title = String::try_from(read_token!(tokens)?)?;
let signature = String::try_from(read_token!(tokens)?)?;
let time_started_recording = f64::try_from(read_token!(tokens)?)?;
let time_stopped_recording = f64::try_from(read_token!(tokens)?)?;
let time_started_recording = OffsetDateTime::try_from(read_token!(tokens)?)?;
let time_stopped_recording = OffsetDateTime::try_from(read_token!(tokens)?)?;
let sub_sections_size = Option::<usize>::try_from(read_token!(tokens)?)?.unwrap_or(0);
let sub_sections = deser_vec(tokens, sub_sections_size, class_position_to_name);
let text = Option::<String>::try_from(read_token!(tokens)?)?;
Expand Down Expand Up @@ -566,8 +571,10 @@ pub struct IDEActivityLogCommandInvocationSection {
pub domain_type: String,
pub title: String,
pub signature: String,
pub time_started_recording: f64,
pub time_stopped_recording: f64,
#[serde(with = "time::serde::iso8601")]
pub time_started_recording: OffsetDateTime,
#[serde(with = "time::serde::iso8601")]
pub time_stopped_recording: OffsetDateTime,
pub sub_sections: Vec<IDEActivityLogSection>,
pub text: Option<String>,
pub messages: Vec<IDEActivityLogMessage>,
Expand All @@ -591,8 +598,8 @@ where
let domain_type = String::try_from(read_token!(tokens)?)?;
let title = String::try_from(read_token!(tokens)?)?;
let signature = String::try_from(read_token!(tokens)?)?;
let time_started_recording = f64::try_from(read_token!(tokens)?)?;
let time_stopped_recording = f64::try_from(read_token!(tokens)?)?;
let time_started_recording = OffsetDateTime::try_from(read_token!(tokens)?)?;
let time_stopped_recording = OffsetDateTime::try_from(read_token!(tokens)?)?;
let sub_sections_size = Option::<usize>::try_from(read_token!(tokens)?)?.unwrap_or(0);
let sub_sections = deser_vec(tokens, sub_sections_size, class_position_to_name);
let text = Option::<String>::try_from(read_token!(tokens)?)?;
Expand Down
Loading

0 comments on commit 5ad1ee8

Please sign in to comment.