Skip to content

Commit 06bb39e

Browse files
committed
Refactor responses to use DateTime<Utc> for timestamp fields
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent 3e04853 commit 06bb39e

File tree

3 files changed

+125
-7
lines changed

3 files changed

+125
-7
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77

88
[dependencies]
99
base64 = "0.22"
10+
chrono = { version = "0.4", features = ["serde"] }
1011
openssl = "0.10"
1112
reqwest = { version = "0.12", features = ["json", "rustls-tls"] }
1213
ring = "0.17"

src/app/response.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use std::fmt;
66

7+
use chrono::{DateTime, Utc};
78
use serde::{Deserialize, Serialize};
89

910
/// Coinbase App error message
@@ -68,9 +69,9 @@ pub struct Account {
6869
/// Account balance
6970
pub balance: Balance,
7071
/// Created at
71-
pub created_at: Option<String>,
72+
pub created_at: Option<DateTime<Utc>>,
7273
/// Updated at
73-
pub updated_at: Option<String>,
74+
pub updated_at: Option<DateTime<Utc>>,
7475
}
7576

7677
/// Account balance
@@ -233,7 +234,7 @@ pub struct Transaction {
233234
/// User defined description
234235
pub description: Option<String>,
235236
/// Created at
236-
pub created_at: Option<String>,
237+
pub created_at: Option<DateTime<Utc>>,
237238
}
238239

239240
fn deserialize_string_to_f64<'de, D>(deserializer: D) -> Result<f64, D::Error>
@@ -301,7 +302,7 @@ mod tests {
301302
assert_eq!(account.balance.currency, "BTC");
302303

303304
// Verify optional fields
304-
assert_eq!(account.created_at, Some("2024-01-31T20:49:02Z".to_string()));
305-
assert_eq!(account.updated_at, Some("2024-01-31T20:49:02Z".to_string()));
305+
assert_eq!(account.created_at.map(|t| t.timestamp()), Some(1706734142));
306+
assert_eq!(account.updated_at.map(|t| t.timestamp()), Some(1706734142));
306307
}
307308
}

0 commit comments

Comments
 (0)