| 35 | |
| 36 | #[expect(clippy::cast_possible_truncation)] |
| 37 | fn to_sql( |
| 38 | &self, |
| 39 | _: &postgres_types::Type, |
| 40 | out: &mut BytesMut, |
| 41 | ) -> Result<postgres_types::IsNull, Box<dyn error::Error + Sync + Send>> |
| 42 | where |
| 43 | Self: Sized, |
| 44 | { |
| 45 | // The value has been determined via `Date.UTC(2000, 0, 1)` in JS, and is the same as the one that jdbc uses: https://jdbc.postgresql.org/documentation/publicapi/constant-values.html |
| 46 | const BASE: i128 = 946_684_800_000; |
| 47 | |
| 48 | // Our timestamp is milliseconds since Unix epoch (1970-01-01). |
| 49 | // Postgres stores microseconds since 2000-01-01. |
| 50 | let value = ((Int::from(self.0).as_int() - BASE) * 1000) as i64; |
| 51 | |
| 52 | postgres_protocol::types::timestamp_to_sql(value, out); |
| 53 | Ok(postgres_types::IsNull::No) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | impl ToSql for Postgres<TemporalInterval> { |