string_utils and decimal_utils; resolves #23 and resolves #22

This commit is contained in:
scoobybejesus 2019-08-25 23:29:22 -04:00
parent dbbf082d5b
commit 82f303f064
8 changed files with 20 additions and 17 deletions

View File

@ -15,7 +15,7 @@ use rustyline::error::ReadlineError;
use rustyline::highlight::{Highlighter};
use crate::core_functions::InventoryCostingMethod;
use crate::utils;
use crate::string_utils;
pub fn choose_file_for_import() -> PathBuf {
@ -194,7 +194,7 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> (bool, Str
let mut input = String::new();
let stdin = io::stdin();
stdin.lock().read_line(&mut input)?;
utils::trim_newline(&mut input);
string_utils::trim_newline(&mut input);
let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")
.expect("Date entered has an incorrect format. Program must abort."));
@ -236,7 +236,7 @@ pub fn elect_like_kind_treatment(cutoff_date_arg: &Option<String>) -> (bool, Str
let mut input = String::new();
let stdin = io::stdin();
stdin.lock().read_line(&mut input)?;
utils::trim_newline(&mut input);
string_utils::trim_newline(&mut input);
let newly_chosen_date = NaiveDate::parse_from_str(&input, "%y-%m-%d")
.unwrap_or(NaiveDate::parse_from_str(&input, "%Y-%m-%d")

View File

@ -11,7 +11,7 @@ use chrono::NaiveDate;
use crate::transaction::{Transaction, ActionRecord, TxType, Polarity, TxHasMargin};
use crate::account::{Account, RawAccount, Lot, Movement};
use crate::core_functions::{InventoryCostingMethod, LikeKindSettings, ImportProcessParameters};
use crate::utils::{round_d128_1e8};
use crate::decimal_utils::{round_d128_1e8};
pub fn create_lots_and_movements(
txns_map: HashMap<u32, Transaction>,

View File

@ -23,12 +23,3 @@ pub fn round_d128_1e8(to_round: &d128) -> d128 {
// As you can see, the quantize is off by one. Quantizing to 10 rounds off the nearest one. Quantizing to 100 rounds off to nearest 10, etc.
}
pub fn trim_newline(s: &mut String) {
if s.ends_with('\n') {
s.pop();
if s.ends_with('\r') {
s.pop();
}
}
}

View File

@ -12,7 +12,7 @@ use decimal::d128;
use crate::transaction::{Transaction, ActionRecord};
use crate::account::{Account, RawAccount};
use crate::utils::{round_d128_1e8};
use crate::decimal_utils::{round_d128_1e8};
pub fn import_accounts(

View File

@ -8,7 +8,7 @@ use decimal::d128;
use crate::transaction::{Transaction, TxType, ActionRecord, Polarity};
use crate::account::{Account, RawAccount};
use crate::utils::{round_d128_1e2};
use crate::decimal_utils::{round_d128_1e2};
use crate::core_functions::{ImportProcessParameters};
pub fn add_cost_basis_to_movements(

View File

@ -23,7 +23,8 @@ mod create_lots_mvmts;
mod import_cost_proceeds_etc;
mod cli_user_choices;
mod csv_export;
mod utils;
mod string_utils;
mod decimal_utils;
mod tests;
use crate::core_functions::ImportProcessParameters;

11
src/string_utils.rs Normal file
View File

@ -0,0 +1,11 @@
// Copyright (c) 2017-2019, scoobybejesus
// Redistributions must include the license: https://github.com/scoobybejesus/cryptools-rs/LEGAL.txt
pub fn trim_newline(s: &mut String) {
if s.ends_with('\n') {
s.pop();
if s.ends_with('\r') {
s.pop();
}
}
}

View File

@ -8,7 +8,7 @@ use decimal::d128;
use crate::account::{Account};
use crate::transaction::{Transaction, ActionRecord};
use crate::utils::*;
use crate::decimal_utils::*;
pub fn run_tests(
transactions_map: &HashMap<u32, Transaction>,