From e6f1c8fbc887e7cdcbdb95d22a13feb165e826ba Mon Sep 17 00:00:00 2001 From: Ragib Badaruddin Date: Mon, 20 Nov 2023 10:39:21 +0800 Subject: [PATCH 1/3] datetime to wire --- convergence/src/to_wire.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/convergence/src/to_wire.rs b/convergence/src/to_wire.rs index cafcce1..c23f8ef 100644 --- a/convergence/src/to_wire.rs +++ b/convergence/src/to_wire.rs @@ -1,5 +1,5 @@ use bytes::BytesMut; -use chrono::{NaiveDate, NaiveDateTime, NaiveTime}; +use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, Utc}; use postgres_types::ToSql; use rust_decimal::Decimal; @@ -81,6 +81,17 @@ impl ToWire for NaiveTime { } } +impl ToWire for DateTime { + fn to_binary(&self) -> Vec { + let mut b = BytesMut::new(); + self.to_sql(&postgres_types::Type::NUMERIC, &mut b).unwrap(); + b.into() + } + fn to_text(&self) -> Vec { + self.to_string().as_bytes().into() + } +} + impl ToWire for Decimal { fn to_binary(&self) -> Vec { let mut b = BytesMut::new(); From 27d7b3d602f428f014f4cc33e16b96fd4db207e5 Mon Sep 17 00:00:00 2001 From: Ragib Badaruddin Date: Mon, 20 Nov 2023 11:11:42 +0800 Subject: [PATCH 2/3] use naive_utc().tobinary() instead --- convergence/src/to_wire.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/convergence/src/to_wire.rs b/convergence/src/to_wire.rs index c23f8ef..c185cd6 100644 --- a/convergence/src/to_wire.rs +++ b/convergence/src/to_wire.rs @@ -83,9 +83,7 @@ impl ToWire for NaiveTime { impl ToWire for DateTime { fn to_binary(&self) -> Vec { - let mut b = BytesMut::new(); - self.to_sql(&postgres_types::Type::NUMERIC, &mut b).unwrap(); - b.into() + self.naive_utc().to_binary() } fn to_text(&self) -> Vec { self.to_string().as_bytes().into() From 117cb3d0a26eb977370ceaf2566f0b4619b883be Mon Sep 17 00:00:00 2001 From: Ragib Badaruddin Date: Mon, 20 Nov 2023 11:30:31 +0800 Subject: [PATCH 3/3] datetime utc to_text using rfc3339 --- convergence/src/to_wire.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convergence/src/to_wire.rs b/convergence/src/to_wire.rs index c185cd6..355e1ed 100644 --- a/convergence/src/to_wire.rs +++ b/convergence/src/to_wire.rs @@ -86,7 +86,7 @@ impl ToWire for DateTime { self.naive_utc().to_binary() } fn to_text(&self) -> Vec { - self.to_string().as_bytes().into() + self.to_rfc3339().as_bytes().into() } }