Skip to content

Commit

Permalink
Fix a number of new Chrono deprecations
Browse files Browse the repository at this point in the history
Most warnings are raised in our test code, where the older API didn't
consider possible failures.
  • Loading branch information
DavidCain committed Jan 6, 2024
1 parent adb33a4 commit 6a86683
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
6 changes: 3 additions & 3 deletions src/compounding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/dateutil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn localize_from_dt_with_tz(datestring: &str) -> ParseResult<DateTime<Local>
// In SQLite, all datetimes are UTC, but without timezone explicitly stated!
pub fn utc_to_datetime(datestring: &str) -> DateTime<Local> {
let dt = NaiveDateTime::parse_from_str(datestring, GNUCASH_NO_DT_FORMAT).unwrap();
let utc = DateTime::<Utc>::from_utc(dt, Utc);
let utc = DateTime::<Utc>::from_naive_utc_and_offset(dt, Utc);
utc.with_timezone(&Local)
}

Expand Down

0 comments on commit 6a86683

Please sign in to comment.