Repository: diesel-rs/diesel
File: diesel/src/sqlite/types/date_and_time/chrono.rs (Rust)

Code before:
            if let Ok(julian_days) = text.parse::<f64>() {
                let epoch_in_julian_days = 2_440_587.5;
                let seconds_in_day = 86400.0;
                let timestamp = (julian_days - epoch_in_julian_days) * seconds_in_day;
                let seconds = timestamp as i64;
                let nanos = (timestamp.fract() * 1E9) as u32;
                if let Some(timestamp) = Self::from_timestamp_opt(seconds, nanos) {
                    return Ok(timestamp);
                }
            }

            Err(format!("Invalid datetime {}", text).into())
        })
    }
}

#[cfg(all(feature = "sqlite", feature = "chrono"))]
impl ToSql<Timestamp, Sqlite> for NaiveDateTime {
    fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Sqlite>) -> serialize::Result {
        out.set_value(self.format("%F %T%.f").to_string());
        Ok(IsNull::No)
    }
}

impl FromSql<TimestamptzSqlite, Sqlite> for NaiveDateTime {
    fn from_sql(value: backend::RawValue<'_, Sqlite>) -> deserialize::Result<Self> {
        value.parse_string(|text| {
            let sqlite_datetime_formats = &[
                "%F %RZ",
                "%F %R%:z",
                "%F %TZ",
                "%F %T%:z",
                "%F %T%.fZ",
                "%F %T%.f%:z",
                "%FT%RZ",
                "%FT%R%:z",
                "%FT%TZ",
                "%FT%T%:z",
                "%FT%T%.fZ",
                "%FT%T%.f%:z",
            ];

            for format in sqlite_datetime_formats {
                if let Ok(dt) = Self::parse_from_str(text, format) {
                    return Ok(dt);
                }
            }

            if let Ok(julian_days) = text.parse::<f64>() {
                let epoch_in_julian_days = 2_440_587.5;
                let seconds_in_day = 86400.0;

Review comment (suggestion):
We should mark these impl with
`#[cfg(all(feature = "sqlite", feature = "chrono")]` so that the corresponding features show up in the API documentation.

(This applies to all other `FromSql`/`ToSql` impls added in this file)

Code after:
            if let Ok(julian_days) = text.parse::<f64>() {
                let epoch_in_julian_days = 2_440_587.5;
                let seconds_in_day = 86400.0;
                let timestamp = (julian_days - epoch_in_julian_days) * seconds_in_day;
                let seconds = timestamp as i64;
                let nanos = (timestamp.fract() * 1E9) as u32;
                if let Some(timestamp) = Self::from_timestamp_opt(seconds, nanos) {
                    return Ok(timestamp);
                }
            }

            Err(format!("Invalid datetime {}", text).into())
        })
    }
}

#[cfg(all(feature = "sqlite", feature = "chrono"))]
impl ToSql<Timestamp, Sqlite> for NaiveDateTime {
    fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Sqlite>) -> serialize::Result {
        out.set_value(self.format("%F %T%.f").to_string());
        Ok(IsNull::No)
    }
}

#[cfg(all(feature = "sqlite", feature = "chrono"))]
impl FromSql<TimestamptzSqlite, Sqlite> for NaiveDateTime {
    fn from_sql(value: backend::RawValue<'_, Sqlite>) -> deserialize::Result<Self> {
        value.parse_string(|text| {
            let sqlite_datetime_formats = &[
                "%F %RZ",
                "%F %R%:z",
                "%F %TZ",
                "%F %T%:z",
                "%F %T%.fZ",
                "%F %T%.f%:z",
                "%FT%RZ",
                "%FT%R%:z",
                "%FT%TZ",
                "%FT%T%:z",
                "%FT%T%.fZ",
                "%FT%T%.f%:z",
            ];

            for format in sqlite_datetime_formats {
                if let Ok(dt) = Self::parse_from_str(text, format) {
                    return Ok(dt);
                }
            }

            if let Ok(julian_days) = text.parse::<f64>() {
                let epoch_in_julian_days = 2_440_587.5;