diff --git a/src/allocation.rs b/src/allocation.rs index ae3a015..bee225b 100644 --- a/src/allocation.rs +++ b/src/allocation.rs @@ -99,19 +99,19 @@ mod tests { #[test] #[should_panic(expected = "You were born in the future?")] fn test_future_birthday() { - let birthday = NaiveDate::from_ymd(2095, 6, 14); + let birthday = NaiveDate::from_ymd_opt(2095, 6, 14).unwrap(); age_in_weeks(birthday); } #[test] fn test_bond_allocation_ancient_investor() { - let birthday = NaiveDate::from_ymd(1863, 11, 19); + let birthday = NaiveDate::from_ymd_opt(1863, 11, 19).unwrap(); assert_eq!(bond_allocation(birthday, 100), Decimal::from(1)); } #[test] fn test_bond_allocation_very_young_investor() { - let birthday = NaiveDate::from_ymd(2018, 12, 30); + let birthday = NaiveDate::from_ymd_opt(2018, 12, 30).unwrap(); assert_eq!(bond_allocation(birthday, 130), Decimal::from(0)); } diff --git a/src/compounding.rs b/src/compounding.rs index 5bc12cc..2a160a1 100644 --- a/src/compounding.rs +++ b/src/compounding.rs @@ -40,14 +40,14 @@ mod tests { #[test] fn test_banking_years() { - let current_date = NaiveDate::from_ymd(2019, 4, 18); - let future_date = NaiveDate::from_ymd(2095, 4, 18); + let current_date = NaiveDate::from_ymd_opt(2019, 4, 18).unwrap(); + let future_date = NaiveDate::from_ymd_opt(2095, 4, 18).unwrap(); assert_eq!(banking_years(current_date, future_date), 76.0); } #[test] fn test_compounding() { - let future_date = NaiveDate::from_ymd(2055, 4, 18); + let future_date = NaiveDate::from_ymd_opt(2055, 4, 18).unwrap(); let total = compound(Decimal::from(100_000), 0.07, future_date); assert!(total > Decimal::from(100_000)); // TODO: This value is hard-coded from today's date (July 9, 2019) diff --git a/src/config.rs b/src/config.rs index 9c7667b..af89006 100644 --- a/src/config.rs +++ b/src/config.rs @@ -82,13 +82,19 @@ mod tests { let user = User { birthday: String::from("1962-12-31"), }; - assert_eq!(user.birthday(), NaiveDate::from_ymd(1962, 12, 31)); + assert_eq!( + user.birthday(), + NaiveDate::from_ymd_opt(1962, 12, 31).unwrap() + ); } #[test] fn test_parse_from_toml() { let conf = Config::from_file("example_config.toml"); - assert_eq!(conf.user_birthday(), NaiveDate::from_ymd(1972, 7, 12)); + assert_eq!( + conf.user_birthday(), + NaiveDate::from_ymd_opt(1972, 7, 12).unwrap() + ); assert_eq!(&conf.gnucash.path_to_book, "/home/linus/sqlite3.gnucash"); assert_eq!(&conf.gnucash.file_format, "sqlite3"); assert_eq!(conf.gnucash.update_prices, true); diff --git a/src/dateutil.rs b/src/dateutil.rs index ab1f1b0..c1128d4 100644 --- a/src/dateutil.rs +++ b/src/dateutil.rs @@ -19,7 +19,7 @@ pub fn localize_from_dt_with_tz(datestring: &str) -> ParseResult // In SQLite, all datetimes are UTC, but without timezone explicitly stated! pub fn utc_to_datetime(datestring: &str) -> DateTime { let dt = NaiveDateTime::parse_from_str(datestring, GNUCASH_NO_DT_FORMAT).unwrap(); - let utc = DateTime::::from_utc(dt, Utc); + let utc = DateTime::::from_naive_utc_and_offset(dt, Utc); utc.with_timezone(&Local) }