Skip to content

Commit aeedb36

Browse files
committed
small fixes and version bump
1 parent 5c458ec commit aeedb36

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = [
99
]
1010

1111
[workspace.package]
12-
version = "0.2.2"
12+
version = "0.2.3"
1313
edition = "2021"
1414
license = "MIT"
1515
repository = "https://github.com/blockscout/actix-prost"

actix-prost-convert-trait/src/datetime.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,13 @@ impl TryConvert<String> for NaiveDateTime {
7878
}
7979
}
8080

81+
82+
// implemented via Debug according to the implementation of the serde module
83+
// https://github.com/chronotope/chrono/blob/e632ffd3b89d3cfaa96776f2368ee4c21a972766/src/naive/datetime/serde.rs#L6-L26
84+
// https://docs.rs/chrono/latest/chrono/naive/struct.NaiveDateTime.html#impl-Debug-for-NaiveDateTime
8185
impl TryConvert<NaiveDateTime> for String {
8286
fn try_convert(value: NaiveDateTime) -> Result<Self, String> {
83-
Ok(value.format("%Y-%m-%dT%H:%M:%S").to_string())
87+
Ok(format!("{:?}", value))
8488
}
8589
}
8690

@@ -197,20 +201,20 @@ mod tests {
197201

198202
#[test]
199203
fn test_conversion_datetime_to_string() {
200-
let datetime = "2021-01-01T00:00:00+00:00"
204+
let datetime = "2021-01-01T00:00:00.123456789+00:00"
201205
.parse::<DateTime<Utc>>()
202206
.unwrap();
203207
let string = String::try_convert(datetime).unwrap();
204-
assert_eq!(string, "2021-01-01T00:00:00+00:00");
208+
assert_eq!(string, "2021-01-01T00:00:00.123456789+00:00");
205209

206-
let datetime = "2021-01-01T00:00:00+00:00"
210+
let datetime = "2021-01-01T00:00:00.123456789+00:00"
207211
.parse::<DateTime<FixedOffset>>()
208212
.unwrap();
209213
let string = String::try_convert(datetime).unwrap();
210-
assert_eq!(string, "2021-01-01T00:00:00+00:00");
214+
assert_eq!(string, "2021-01-01T00:00:00.123456789+00:00");
211215

212-
let datetime = "2021-01-01T00:00:00".parse::<NaiveDateTime>().unwrap();
216+
let datetime = "2021-01-01T00:00:00.123456789".parse::<NaiveDateTime>().unwrap();
213217
let string = String::try_convert(datetime).unwrap();
214-
assert_eq!(string, "2021-01-01T00:00:00");
218+
assert_eq!(string, "2021-01-01T00:00:00.123456789");
215219
}
216220
}

0 commit comments

Comments
 (0)