Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
15 changes: 13 additions & 2 deletions src/chrono_04.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use chrono_04::{DateTime, NaiveDateTime, TimeZone};
use chrono_04::{DateTime, NaiveDateTime, TimeZone, NaiveDate};

use crate::{Normalizable, RangeBound, BoundSided};

Expand All @@ -20,4 +20,15 @@ impl Normalizable for NaiveDateTime
{
bound
}
}
}


impl Normalizable for NaiveDate
{
fn normalize<S>(bound: RangeBound<S, NaiveDate>) -> RangeBound<S, NaiveDate>
where
S: BoundSided,
{
bound
}
}
27 changes: 20 additions & 7 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mod test {
use postgres::{Client, NoTls};
use postgres::types::{FromSql, ToSql};
#[cfg(feature = "with-chrono-0_4")]
use chrono_04::{TimeZone, Utc, Duration};
use chrono_04::{NaiveDate, NaiveTime, NaiveDateTime, TimeZone, Utc, Duration};

macro_rules! test_range {
($name:expr, $t:ty, $low:expr, $low_str:expr, $high:expr, $high_str:expr) => ({
Expand Down Expand Up @@ -152,11 +152,11 @@ mod test {
let stmt = conn.prepare(&*format!("SELECT {}::{}", *repr, sql_type))
.unwrap();
let result = conn.query(&stmt, &[]).unwrap().iter().next().unwrap().get(0);
assert!(val == &result);
assert_eq!(val, &result);

let stmt = conn.prepare(&*format!("SELECT $1::{}", sql_type)).unwrap();
let result = conn.query(&stmt, &[val]).unwrap().iter().next().unwrap().get(0);
assert!(val == &result);
assert_eq!(val, &result);
}
}

Expand All @@ -173,16 +173,29 @@ mod test {
#[test]
#[cfg(feature = "with-chrono-0_4")]
fn test_tsrange_params() {
let low = Utc.timestamp(0, 0);
let d = NaiveDate::from_ymd_opt(2015, 6, 3).unwrap();
let t = NaiveTime::from_hms_milli_opt(12, 34, 56, 789).unwrap();

let low = NaiveDateTime::new(d, t);
let high = low + Duration::days(10);
test_range!("TSRANGE", NaiveDateTime, low.naive_utc(), "1970-01-01", high.naive_utc(), "1970-01-11");
test_range!("TSRANGE", NaiveDateTime, low, "2015-06-03T12:34:56.789", high, "2015-06-13T12:34:56.789");
}

#[test]
#[cfg(feature = "with-chrono-0_4")]
fn test_tstzrange_params() {
let low = Utc.timestamp(0, 0);
let low = Utc.with_ymd_and_hms(2014, 7, 8, 9, 10, 11).unwrap();
let high = low + Duration::days(10);
test_range!("TSTZRANGE", DateTime<_>, low, "2014-07-08T09:10:11Z", high, "2014-07-18T09:10:11Z");
}


#[test]
#[cfg(feature = "with-chrono-0_4")]
#[ignore = "Exclusive starts will be converted to next-day + inclusive"]
fn test_daterange_params() {
let low = NaiveDate::from_ymd_opt(2015, 6, 4).unwrap();
let high = low + Duration::days(10);
test_range!("TSTZRANGE", DateTime<Utc>, low, "1970-01-01", high, "1970-01-11");
test_range!("DATERANGE", NaiveDate, low, "2015-06-04", high, "2015-06-14");
}
}