use chrono::{Date, DateTime, Datelike, TimeZone};
#[cfg(test)]
mod test {
use super::*;
use chrono::Utc;
#[test]
fn begin_of_month_test() {
let date = Utc.ymd(2008, 8, 8);
let actual = Utc.ymd(2008, 8, 1);
let result = begin_of_month(date);
assert_eq!(actual, result);
}
#[test]
fn begin_of_month_with_time_test() {
let datetime = Utc.ymd(2008, 8, 8).and_hms(8, 8, 8);
let actual = Utc.ymd(2008, 8, 1);
let result = begin_of_month_with_time(datetime);
assert_eq!(actual, result);
}
}
pub fn begin_of_month<Tz: TimeZone>(date: Date<Tz>) -> Date<Tz> {
date.with_day(1).unwrap()
}
pub fn begin_of_month_with_time<Tz: TimeZone>(datetime: DateTime<Tz>) -> Date<Tz> {
datetime.date().with_day(1).unwrap()
}