Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deprecated chrono methods #276

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/appender.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate duckdb;
use std::convert::TryFrom;

use duckdb::{params, Connection, DropBehavior, Result};

Expand Down
3 changes: 1 addition & 2 deletions src/appender/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{ffi, AppenderParams, Connection, Result, ValueRef};
use std::{ffi::c_void, fmt, iter::IntoIterator, os::raw::c_char};
use std::{ffi::c_void, fmt, os::raw::c_char};

use crate::{
error::result_from_duckdb_appender,
Expand Down Expand Up @@ -170,7 +170,6 @@ impl fmt::Debug for Appender<'_> {
#[cfg(test)]
mod test {
use crate::{Connection, Result};
use std::convert::TryFrom;

#[test]
fn test_append_one_row() -> Result<()> {
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ pub use libduckdb_sys as ffi;
use std::{
cell::RefCell,
convert,
default::Default,
ffi::CString,
fmt,
path::{Path, PathBuf},
Expand Down
2 changes: 1 addition & 1 deletion src/r2d2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl r2d2::ManageConnection for DuckdbConnectionManager {
mod test {
extern crate r2d2;
use super::*;
use crate::{types::Value, Result};
use crate::types::Value;
use std::{sync::mpsc, thread};

use tempdir::TempDir;
Expand Down
2 changes: 1 addition & 1 deletion src/raw_statement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{convert::TryFrom, ffi::CStr, ptr, rc::Rc, sync::Arc};
use std::{ffi::CStr, ptr, rc::Rc, sync::Arc};

use arrow::{
array::StructArray,
Expand Down
2 changes: 1 addition & 1 deletion src/statement.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{convert, ffi::c_void, fmt, iter::IntoIterator, mem, os::raw::c_char, ptr, str};
use std::{convert, ffi::c_void, fmt, mem, os::raw::c_char, ptr, str};

use arrow::{array::StructArray, datatypes::DataType};

Expand Down
15 changes: 9 additions & 6 deletions src/types/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ impl FromSql for NaiveDateTime {
TimeUnit::Microsecond => (t / 1_000_000, (t % 1_000_000) * 1000),
TimeUnit::Nanosecond => (t / 1_000_000_000, t % 1_000_000_000),
};
Ok(NaiveDateTime::from_timestamp_opt(secs, nsecs as u32).unwrap())
}
ValueRef::Date32(d) => Ok(NaiveDateTime::from_timestamp_opt(24 * 3600 * (d as i64), 0).unwrap()),
ValueRef::Time64(TimeUnit::Microsecond, d) => {
Ok(NaiveDateTime::from_timestamp_opt(d / 1_000_000, ((d % 1_000_000) * 1_000) as u32).unwrap())
Ok(DateTime::from_timestamp(secs, nsecs as u32).unwrap().naive_utc())
}
ValueRef::Date32(d) => Ok(DateTime::from_timestamp(24 * 3600 * (d as i64), 0).unwrap().naive_utc()),
ValueRef::Time64(TimeUnit::Microsecond, d) => Ok(DateTime::from_timestamp(
d / 1_000_000,
((d % 1_000_000) * 1_000) as u32,
)
.unwrap()
.naive_utc()),
ValueRef::Text(s) => {
let mut s = std::str::from_utf8(s).unwrap();
let format = match s.len() {
Expand Down Expand Up @@ -206,7 +209,7 @@ mod test {
assert_eq!(utc, v2);

let v3: DateTime<Utc> = db.query_row("SELECT '2016-02-23 23:56:04'", [], |r| r.get(0))?;
assert_eq!(utc - Duration::milliseconds(789), v3);
assert_eq!(utc - Duration::try_milliseconds(789).unwrap(), v3);

let v4: DateTime<Utc> = db.query_row("SELECT '2016-02-23 23:56:04.789+00:00'", [], |r| r.get(0))?;
assert_eq!(utc, v4);
Expand Down
1 change: 0 additions & 1 deletion src/types/from_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ impl FromSql for Value {
mod test {
use super::FromSql;
use crate::{Connection, Error, Result};
use std::convert::TryFrom;

#[test]
fn test_timestamp_raw() -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions src/vtab/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use super::{
use crate::vtab::vector::Inserter;
use arrow::array::{
as_boolean_array, as_large_list_array, as_list_array, as_primitive_array, as_string_array, Array, ArrayData,
ArrowPrimitiveType, BooleanArray, Decimal128Array, FixedSizeListArray, GenericListArray, OffsetSizeTrait,
PrimitiveArray, StringArray, StructArray,
BooleanArray, Decimal128Array, FixedSizeListArray, GenericListArray, OffsetSizeTrait, PrimitiveArray, StringArray,
StructArray,
};

use arrow::{
Expand Down
1 change: 0 additions & 1 deletion src/vtab/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ impl InnerConnection {
#[cfg(test)]
mod test {
use super::*;
use crate::{Connection, Result};
use std::{
error::Error,
ffi::{c_char, CString},
Expand Down
Loading