Skip to content

Commit fa5615b

Browse files
AmmarAbouZormarcmo
authored andcommitted
Remove humantime dependency
* Use built-in time formatter from chrono library instead of the unmaintained `humantime` crate. * Using the new format method discovered a bug in formatting the time when there are no fractional seconds making the width of the output not always the same. * Snapshot test results adjusted after resolving the bug.
1 parent e025adc commit fa5615b

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

application/apps/indexer/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

application/apps/indexer/parsers/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ byteorder = "1.5"
88
chrono = "0.4"
99
chrono-tz = "0.10"
1010
dlt-core.workspace = true
11-
humantime = "2.1"
1211
lazy_static.workspace = true
1312
log.workspace = true
1413
regex.workspace = true

application/apps/indexer/parsers/src/dlt/fmt.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
//! # Formatting dlt messages as text
1414
use crate::someip::{FibexMetadata as FibexSomeipMetadata, SomeipParser};
15-
use chrono::prelude::{DateTime, Utc};
15+
use chrono::{
16+
prelude::{DateTime, Utc},
17+
TimeZone,
18+
};
1619
use chrono_tz::Tz;
1720
use dlt_core::{
1821
dlt::{
@@ -143,8 +146,7 @@ impl fmt::Display for DltDltTimeStamp<'_> {
143146
DateTime::from_timestamp(i64::from(self.0.seconds), self.0.microseconds * 1000);
144147
match dt {
145148
Some(dt) => {
146-
let system_time: std::time::SystemTime = std::time::SystemTime::from(dt);
147-
write!(f, "{}", humantime::format_rfc3339(system_time))
149+
write!(f, "{}", format_time_rfc3339(&dt))
148150
}
149151
None => write!(
150152
f,
@@ -155,6 +157,11 @@ impl fmt::Display for DltDltTimeStamp<'_> {
155157
}
156158
}
157159

160+
/// Formats the provided date time according to `RFC3339`
161+
fn format_time_rfc3339<Tz: TimeZone>(dt: &DateTime<Tz>) -> String {
162+
dt.to_rfc3339_opts(chrono::SecondsFormat::Nanos, true)
163+
}
164+
158165
// EColumn.DATETIME,
159166
// EColumn.ECUID,
160167
struct DltStandardHeader<'a>(&'a StandardHeader);
@@ -650,20 +657,17 @@ fn write_tz_string(
650657
}
651658

652659
pub fn utc_string(time_stamp: &DltTimeStamp) -> String {
653-
let dt: Option<DateTime<Utc>> = DateTime::from_timestamp(
660+
DateTime::from_timestamp(
654661
i64::from(time_stamp.seconds),
655662
time_stamp.microseconds * 1000,
656-
);
657-
match dt {
658-
Some(dt) => {
659-
let system_time: std::time::SystemTime = std::time::SystemTime::from(dt);
660-
humantime::format_rfc3339(system_time).to_string()
661-
}
662-
None => format!(
663+
)
664+
.map(|dt| format_time_rfc3339(&dt))
665+
.unwrap_or_else(|| {
666+
format!(
663667
"no valid timestamp for {}s/{}us",
664668
time_stamp.seconds, time_stamp.microseconds,
665-
),
666-
}
669+
)
670+
})
667671
}
668672

669673
fn message_type(msg: &Message, message_info: Option<&str>) -> Option<MessageType> {

application/apps/indexer/session/tests/snapshot_tests/snapshots/observe_dlt_session.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ info:
99
snapshot_kind: text
1010
---
1111
session_file:
12-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu1\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLST\u0005129721424\u0005test1.txt\u00055\u0005date\u00051\u00050\u0005FLST"
13-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu2\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLST\u00051005083951\u0005test2.txt\u00056\u0005date\u00051\u00050\u0005FLST"
14-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu1\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLDA\u0005129721424\u00051\u0005[74, 65, 73, 74, 31]\u0005FLDA"
15-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu2\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLDA\u00051005083951\u00051\u0005[74, 65, 73, 74, 32, 32]\u0005FLDA"
16-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu3\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLST\u00052406339683\u0005test3.txt\u00057\u0005date\u00051\u00050\u0005FLST"
17-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu3\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLDA\u00052406339683\u00051\u0005[74, 65, 73, 74, 33, 33, 33]\u0005FLDA"
18-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu1\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLFI\u0005129721424\u0005FLFI"
19-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu2\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLFI\u00051005083951\u0005FLFI"
20-
- "1970-01-01T00:00:00Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu3\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLFI\u00052406339683\u0005FLFI"
12+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu1\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLST\u0005129721424\u0005test1.txt\u00055\u0005date\u00051\u00050\u0005FLST"
13+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu2\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLST\u00051005083951\u0005test2.txt\u00056\u0005date\u00051\u00050\u0005FLST"
14+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu1\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLDA\u0005129721424\u00051\u0005[74, 65, 73, 74, 31]\u0005FLDA"
15+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu2\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLDA\u00051005083951\u00051\u0005[74, 65, 73, 74, 32, 32]\u0005FLDA"
16+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu3\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLST\u00052406339683\u0005test3.txt\u00057\u0005date\u00051\u00050\u0005FLST"
17+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu3\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLDA\u00052406339683\u00051\u0005[74, 65, 73, 74, 33, 33, 33]\u0005FLDA"
18+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu1\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLFI\u0005129721424\u0005FLFI"
19+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu2\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLFI\u00051005083951\u0005FLFI"
20+
- "1970-01-01T00:00:00.000000000Z\u0004ecu\u00040\u0004\u00040\u0004\u0004ecu3\u0004\u0004\u0004LogLevel INFO\u0004\u0005FLFI\u00052406339683\u0005FLFI"
2121
attachments:
2222
- filename: test1.txt
2323
content:

application/apps/rustcore/rs-bindings/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/chipmunk-cli/Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)