Skip to content

Commit d885c37

Browse files
authored
Avoid deprecated chrono methods (#276)
* avoid deprecated chrono methods * remove redundant imports...?
1 parent f144f29 commit d885c37

File tree

10 files changed

+15
-17
lines changed

10 files changed

+15
-17
lines changed

examples/appender.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
extern crate duckdb;
2-
use std::convert::TryFrom;
32

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

src/appender/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{ffi, AppenderParams, Connection, Result, ValueRef};
2-
use std::{ffi::c_void, fmt, iter::IntoIterator, os::raw::c_char};
2+
use std::{ffi::c_void, fmt, os::raw::c_char};
33

44
use crate::{
55
error::result_from_duckdb_appender,
@@ -170,7 +170,6 @@ impl fmt::Debug for Appender<'_> {
170170
#[cfg(test)]
171171
mod test {
172172
use crate::{Connection, Result};
173-
use std::convert::TryFrom;
174173

175174
#[test]
176175
fn test_append_one_row() -> Result<()> {

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub use libduckdb_sys as ffi;
6060
use std::{
6161
cell::RefCell,
6262
convert,
63-
default::Default,
6463
ffi::CString,
6564
fmt,
6665
path::{Path, PathBuf},

src/r2d2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl r2d2::ManageConnection for DuckdbConnectionManager {
102102
mod test {
103103
extern crate r2d2;
104104
use super::*;
105-
use crate::{types::Value, Result};
105+
use crate::types::Value;
106106
use std::{sync::mpsc, thread};
107107

108108
use tempdir::TempDir;

src/raw_statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{convert::TryFrom, ffi::CStr, ptr, rc::Rc, sync::Arc};
1+
use std::{ffi::CStr, ptr, rc::Rc, sync::Arc};
22

33
use arrow::{
44
array::StructArray,

src/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{convert, ffi::c_void, fmt, iter::IntoIterator, mem, os::raw::c_char, ptr, str};
1+
use std::{convert, ffi::c_void, fmt, mem, os::raw::c_char, ptr, str};
22

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

src/types/chrono.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ impl FromSql for NaiveDateTime {
6363
TimeUnit::Microsecond => (t / 1_000_000, (t % 1_000_000) * 1000),
6464
TimeUnit::Nanosecond => (t / 1_000_000_000, t % 1_000_000_000),
6565
};
66-
Ok(NaiveDateTime::from_timestamp_opt(secs, nsecs as u32).unwrap())
67-
}
68-
ValueRef::Date32(d) => Ok(NaiveDateTime::from_timestamp_opt(24 * 3600 * (d as i64), 0).unwrap()),
69-
ValueRef::Time64(TimeUnit::Microsecond, d) => {
70-
Ok(NaiveDateTime::from_timestamp_opt(d / 1_000_000, ((d % 1_000_000) * 1_000) as u32).unwrap())
66+
Ok(DateTime::from_timestamp(secs, nsecs as u32).unwrap().naive_utc())
7167
}
68+
ValueRef::Date32(d) => Ok(DateTime::from_timestamp(24 * 3600 * (d as i64), 0).unwrap().naive_utc()),
69+
ValueRef::Time64(TimeUnit::Microsecond, d) => Ok(DateTime::from_timestamp(
70+
d / 1_000_000,
71+
((d % 1_000_000) * 1_000) as u32,
72+
)
73+
.unwrap()
74+
.naive_utc()),
7275
ValueRef::Text(s) => {
7376
let mut s = std::str::from_utf8(s).unwrap();
7477
let format = match s.len() {
@@ -206,7 +209,7 @@ mod test {
206209
assert_eq!(utc, v2);
207210

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

211214
let v4: DateTime<Utc> = db.query_row("SELECT '2016-02-23 23:56:04.789+00:00'", [], |r| r.get(0))?;
212215
assert_eq!(utc, v4);

src/types/from_sql.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ impl FromSql for Value {
272272
mod test {
273273
use super::FromSql;
274274
use crate::{Connection, Error, Result};
275-
use std::convert::TryFrom;
276275

277276
#[test]
278277
fn test_timestamp_raw() -> Result<()> {

src/vtab/arrow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use super::{
66
use crate::vtab::vector::Inserter;
77
use arrow::array::{
88
as_boolean_array, as_large_list_array, as_list_array, as_primitive_array, as_string_array, Array, ArrayData,
9-
ArrowPrimitiveType, BooleanArray, Decimal128Array, FixedSizeListArray, GenericListArray, OffsetSizeTrait,
10-
PrimitiveArray, StringArray, StructArray,
9+
BooleanArray, Decimal128Array, FixedSizeListArray, GenericListArray, OffsetSizeTrait, PrimitiveArray, StringArray,
10+
StructArray,
1111
};
1212

1313
use arrow::{

src/vtab/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ impl InnerConnection {
163163
#[cfg(test)]
164164
mod test {
165165
use super::*;
166-
use crate::{Connection, Result};
167166
use std::{
168167
error::Error,
169168
ffi::{c_char, CString},

0 commit comments

Comments
 (0)