Crates.io | costoflife |
lib.rs | costoflife |
version | 0.3.2 |
source | src |
created_at | 2021-01-03 19:53:25.450309 |
updated_at | 2022-05-03 10:29:21.414599 |
description | The CostOf.Life Calculator |
homepage | https://thecostof.life |
repository | https://github.com/noandrea/costoflife-rs |
max_upload_size | |
id | 331178 |
size | 96,536 |
This is the CostOf.Life library and command line client.
For a more general description about the project check website: thecostof.life
install it with cargo install costoflife
To add a single transaction use the command costoflife add
:
|> costoflife add Netflix 7.99€ 100320 1m12x .movies .covid
See it in action:
The library interpret transactions and calculate for each transaction its per diem amount. For a longer explanation check the CostOf.life website.
A transaction as the properties:
As a simple interface the library interprets strings into transactions, the format of the string is shown in the examples and the details are listed below.
The library tokenize the input string and looks for the patterns listed below. Anything that cannot be recognized as a pattern it will set as the title of the transaction. The title is required
The monetary value of the transaction, required:
Amount ::= Natural ( '.' Digit Digit? )? "€"
Natural ::= NaturalDigit Digit*
NaturalDigit ::= #'[1-9]'
Digit ::= "0" | NaturalDigit
Currently the only available currency is €
Examples:
10€
10000.99€
The duration of transaction, optional, defaults to 1d
.
Lifetime ::= Duration Repeat?
Duration ::= Natural TimeUnit
Repeat ::= Natural "x"
TimeUnit ::= "d" | "w" | "m" | "y"
where the TimeUnit
is:
d
daysw
weeksm
monthsy
yearsExamples:
1m12x
=> one month for 12 times, for example for monthly expenses like monthly subscriptions (Netflix, etc)12m
=> twelve months for 1 time, same as 1y
1w52x
=> one week 52 times, for example weekly groceries expenses for all the year💡 the number of repeats they influence the total amount of the transaction:
10€ 1m12x
will result of a transaction of total amount of120€
while12m1x
will result in a single transaction of10€
over 12 months
The transaction start date, optional, defaults to the current date, it uses the little endian format (day, month, year).
Date ::= Day Month Year
Month ::= "1" #'[0-2]' | "0" NaturalDigit
Day ::= '0' #'[1-9]' | #'[1-2]' Digit | '3' #'[0-1]'
Year ::= Digit Digit
Natural ::= NaturalDigit Digit*
NaturalDigit ::= #'[1-9]'
Digit ::= "0" | NaturalDigit
Examples:
030521
=> March the 3rd, 2021312122
=> December the 31st, 2022To label transactions, optional. For convenience it uses the hashtag format.
HashTag ::= ('#' | '.') Word
EOL ::= '\r'? '\n'
Word ::= AlphaNum+ [ (' ' | '\t')+ | EOL ]
AlphaNum ::= #'[A-Za-z0-9_-]'
Examples:
#lifestile
.whatever
Here the full grammar
Tx ::= ( Amount | Lifetime | StartDate | HashTag ) ( SEP ( Amount | Lifetime | StartDate | HashTag ) )+ EOL
EOL ::= '\r'? '\n'
SEP ::= (' ' | '\t')+
Lifetime ::= Duration Repeat?
Duration ::= Natural TimeUnit
Repeat ::= Natural "x"
TimeUnit ::= "d" | "w" | "m" | "y"
StartDate ::= Day Month Year
Month ::= "1" #'[0-2]' | "0" NaturalDigit
Day ::= '0' #'[1-9]' | #'[1-2]' Digit | '3' #'[0-1]'
Year ::= Digit Digit
Amount ::= Natural ( '.' Digit Digit? )? "€"
Natural ::= NaturalDigit Digit*
NaturalDigit ::= #'[1-9]'
Digit ::= "0" | NaturalDigit
Int ::= "+" | "-" Digit+
HashTag ::= ('#' | '.') Word
Word ::= AlphaNum+
AlphaNum ::= #'[A-Za-z0-9_-]'
Made by adgb
cargo install cargo-edit
. Cargo edit is used to manage dependencies.cargo install cargo-bump
. Cargo bump is used to bump release versions.