Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Cargo.toml: depend on more minimal chrono feature set (#418)
Browse files Browse the repository at this point in the history
* fix chrono failures in CI

* Cargo.toml: depend on more minimal chrono feature set

Disable the default features. Specifically so that wasm-bindgen won't be included if not necessary, as it is a rather intrusive library.

* Format Rust code using rustfmt

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
tomhoule and github-actions[bot] committed Nov 15, 2022
1 parent 08831df commit 657a56a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ hex = "0.4"

either = { version = "1.6", optional = true }
base64 = { version = "0.12.3", optional = true }
chrono = { version = "0.4", optional = true }
chrono = { version = "0.4", optional = true, default-features = false }
lru-cache = { version = "0.1", optional = true }
serde_json = { version = "1.0.48", optional = true, features = ["float_roundtrip"] }
native-tls = { version = "0.2", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/ast/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ mod tests {
#[test]
#[cfg(feature = "chrono")]
fn display_format_for_date() {
let date = NaiveDate::from_ymd(2022, 8, 11);
let date = NaiveDate::from_ymd_opt(2022, 8, 11).unwrap();
let pv = Value::date(date);

assert_eq!(format!("{}", pv), "\"2022-08-11\"");
Expand Down
7 changes: 4 additions & 3 deletions src/connector/mysql/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ impl TakeRow for my::Row {
return Err(Error::builder(kind).build());
}

let time = NaiveTime::from_hms_micro(hour.into(), min.into(), sec.into(), micro);
let time = NaiveTime::from_hms_micro_opt(hour.into(), min.into(), sec.into(), micro).unwrap();

let date = NaiveDate::from_ymd(year.into(), month.into(), day.into());
let date = NaiveDate::from_ymd_opt(year.into(), month.into(), day.into()).unwrap();
let dt = NaiveDateTime::new(date, time);

Value::datetime(DateTime::<Utc>::from_utc(dt, Utc))
Expand All @@ -306,7 +306,8 @@ impl TakeRow for my::Row {
return Err(Error::builder(kind).build());
}

let time = NaiveTime::from_hms_micro(hours.into(), minutes.into(), seconds.into(), micros);
let time =
NaiveTime::from_hms_micro_opt(hours.into(), minutes.into(), seconds.into(), micros).unwrap();
Value::time(time)
}
my::Value::NULL => match column {
Expand Down
4 changes: 1 addition & 3 deletions src/connector/postgres/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,7 @@ impl<'a> ToSql for Value<'a> {
#[cfg(feature = "uuid")]
(Value::Uuid(value), _) => value.map(|value| value.to_sql(ty, out)),
#[cfg(feature = "chrono")]
(Value::DateTime(value), &PostgresType::DATE) => {
value.map(|value| value.date().naive_utc().to_sql(ty, out))
}
(Value::DateTime(value), &PostgresType::DATE) => value.map(|value| value.date_naive().to_sql(ty, out)),
#[cfg(feature = "chrono")]
(Value::Date(value), _) => value.map(|value| value.to_sql(ty, out)),
#[cfg(feature = "chrono")]
Expand Down
25 changes: 12 additions & 13 deletions src/connector/sqlite/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ impl<'a> GetRow for SqliteRow<'a> {
}
#[cfg(feature = "chrono")]
c if c.is_date() => {
let dt = chrono::NaiveDateTime::from_timestamp(i / 1000, 0);
let dt = chrono::NaiveDateTime::from_timestamp_opt(i / 1000, 0).unwrap();
Value::date(dt.date())
}
#[cfg(feature = "chrono")]
c if c.is_datetime() => {
let dt = chrono::Utc.timestamp_millis(i);
let dt = chrono::Utc.timestamp_millis_opt(i).unwrap();
Value::datetime(dt)
}
c if c.is_int32() => {
Expand Down Expand Up @@ -287,18 +287,17 @@ impl<'a> ToSql for Value<'a> {
#[cfg(feature = "chrono")]
Value::DateTime(value) => value.map(|value| ToSqlOutput::from(value.timestamp_millis())),
#[cfg(feature = "chrono")]
Value::Date(date) => date.map(|date| {
let dt = date.and_hms(0, 0, 0);
ToSqlOutput::from(dt.timestamp_millis())
}),
Value::Date(date) => date
.and_then(|date| date.and_hms_opt(0, 0, 0))
.map(|dt| ToSqlOutput::from(dt.timestamp_millis())),
#[cfg(feature = "chrono")]
Value::Time(time) => time.map(|time| {
use chrono::{NaiveDate, Timelike};

let dt = NaiveDate::from_ymd(1970, 1, 1).and_hms(time.hour(), time.minute(), time.second());

ToSqlOutput::from(dt.timestamp_millis())
}),
Value::Time(time) => time
.and_then(|time| chrono::NaiveDate::from_ymd_opt(1970, 1, 1).map(|d| (d, time)))
.and_then(|(date, time)| {
use chrono::Timelike;
date.and_hms_opt(time.hour(), time.minute(), time.second())
})
.map(|dt| ToSqlOutput::from(dt.timestamp_millis())),
};

match value {
Expand Down

0 comments on commit 657a56a

Please sign in to comment.