Struct costoflife::TxRecord
source · [−]pub struct TxRecord { /* private fields */ }
Implementations
sourceimpl TxRecord
impl TxRecord
Holds a transaction informations
pub fn get_name(&self) -> &str
Get the tags for the tx, sorted alphabetically
sourcepub fn get_amount(&self) -> BigDecimal
pub fn get_amount(&self) -> BigDecimal
Get the amount for the tx, rounded to 2 decimals
sourcepub fn get_lifetime(&self) -> &Lifetime
pub fn get_lifetime(&self) -> &Lifetime
Get the lifetime for the tx
sourcepub fn get_starts_on(&self) -> NaiveDate
pub fn get_starts_on(&self) -> NaiveDate
Get the start date for the tx
sourcepub fn get_recorded_at(&self) -> &DateTime<FixedOffset>
pub fn get_recorded_at(&self) -> &DateTime<FixedOffset>
Get the datetime when the tx was recorded
sourcepub fn get_recorded_at_rfc3339(&self) -> String
pub fn get_recorded_at_rfc3339(&self) -> String
Get the datetime when the tx was recorded as a rfc3339 string
sourcepub fn amount_is_total(&self) -> bool
pub fn amount_is_total(&self) -> bool
Returns true if the base amount is the same as the total
That is, when there is no repetition on the lifetime
sourcepub fn get_amount_total(&self) -> BigDecimal
pub fn get_amount_total(&self) -> BigDecimal
Returns total amount for the transaction record
sourcepub fn get_duration_days(&self) -> i64
pub fn get_duration_days(&self) -> i64
Returns the duration in days for this transaction
sourcepub fn per_diem(&self) -> BigDecimal
pub fn per_diem(&self) -> BigDecimal
Calculates and returns the per diem for the record and round it to the 2 decimals
sourcepub fn per_diem_raw(&self) -> BigDecimal
pub fn per_diem_raw(&self) -> BigDecimal
Calculates and returns the per diem for the record
The per diem is calculated as follow:
- END_DAY = START_DAY + (RECURRENCE_SIZE_DAYS * SEC_IN_DAYS * RECURRENCE_TIMES)
- PER_DIEM = AMOUNT * RECURRENCE_TIMES) / (END_DAY - START_DAY )
sourcepub fn get_progress(&self, d: Option<NaiveDate>) -> f32
pub fn get_progress(&self, d: Option<NaiveDate>) -> f32
Get the progress of the transaction at date
None will use today as a data
sourcepub fn get_ends_on(&self) -> NaiveDate
pub fn get_ends_on(&self) -> NaiveDate
Returns the end date (always computed)
pub fn is_active_on(&self, target: &NaiveDate) -> bool
sourcepub fn to_string_record(&self) -> String
pub fn to_string_record(&self) -> String
Serialize the record to its string format
pub fn from_string_record(s: &str) -> Result<TxRecord, CostOfLifeError>
pub fn new(name: &str, amount: &str) -> Result<TxRecord, CostOfLifeError>
sourcepub fn from(
name: &str,
tags: Vec<&str>,
amount: &str,
starts_on: NaiveDate,
lifetime: Lifetime,
recorded_at: DateTime<FixedOffset>,
src: Option<&str>
) -> Result<TxRecord, CostOfLifeError>
pub fn from(
name: &str,
tags: Vec<&str>,
amount: &str,
starts_on: NaiveDate,
lifetime: Lifetime,
recorded_at: DateTime<FixedOffset>,
src: Option<&str>
) -> Result<TxRecord, CostOfLifeError>
Builds a TxRecord using parameters
Arguments
name
- A string slice that holds the name of the transactiontags
- A vector of string slices with the transaction’s tagsamount
- A string slice representing a monetary valuestarts_on
- The date of the start of the transactionlifetime
- The lifetime of transactionrecorded_at
- The localized exact time when the tx was addedsrc
- An option string slice with the original string used to submit the tx
Examples
use costoflife::{self, TxRecord, Lifetime};
let tx = TxRecord::from(
"Car",
vec!["transportation", "lifestyle"],
"100000",
costoflife::date(01, 01, 2010),
Lifetime::Year {
amount: 20,
times: 1,
},
costoflife::now_local(),
None,
).unwrap();
Trait Implementations
sourceimpl FromStr for TxRecord
impl FromStr for TxRecord
type Err = CostOfLifeError
type Err = CostOfLifeError
The associated error which can be returned from parsing.
Auto Trait Implementations
impl RefUnwindSafe for TxRecord
impl Send for TxRecord
impl Sync for TxRecord
impl Unpin for TxRecord
impl UnwindSafe for TxRecord
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more