use chrono::{DateTime, Duration, TimeZone, Timelike, Utc};
pub fn days_ago(n: i64) -> DateTime<Utc> {
Utc::now() - Duration::days(n)
}
pub fn days_from_now(n: i64) -> DateTime<Utc> {
Utc::now() + Duration::days(n)
}
pub fn hours_ago(n: i64) -> DateTime<Utc> {
Utc::now() - Duration::hours(n)
}
pub fn beginning_of_day<Tz: TimeZone>(dt: DateTime<Tz>) -> DateTime<Tz> {
dt.with_hour(0)
.and_then(|d| d.with_minute(0))
.and_then(|d| d.with_second(0))
.and_then(|d| d.with_nanosecond(0))
.unwrap_or(dt)
}
pub fn end_of_day<Tz: TimeZone>(dt: DateTime<Tz>) -> DateTime<Tz> {
dt.with_hour(23)
.and_then(|d| d.with_minute(59))
.and_then(|d| d.with_second(59))
.and_then(|d| d.with_nanosecond(0))
.unwrap_or(dt)
}