Invalid date format when reading ledger file
Hi,
I use dd/mm/yyyy format in my ledger file. I saw this pull which introduced date formatting for output string.
My problem occurs before and the output looks like ...
While parsing file "***/personal.ledger", line 39:
While parsing transaction:
> 26/02/2020 ***
Error: Year is out of valid range: 1400..10000
...
While parsing file "***/personal.ledger", line 84:
While parsing transaction:
> 03/03/2020 ***
Error: Invalid date: 03/03/2020
...
Traceback (most recent call last):
File "***/.pyenv/versions/3.6.9/bin/ledger-autosync", line 11, in <module>
load_entry_point('ledger-autosync==1.0.1', 'console_scripts', 'ledger-autosync')()
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/cli.py", line 363, in run
import_ofx(ledger, args)
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/cli.py", line 160, in import_ofx
ofx.account.account_id)
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/sync.py", line 95, in filter
retval = [txn for txn in sorted_txns
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/sync.py", line 96, in <listcomp>
if not(self.is_txn_synced(acctid, txn))]
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/sync.py", line 59, in is_txn_synced
return self.lgr.check_transaction_by_id("ofxid", ofxid)
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/ledgerwrap.py", line 166, in check_transaction_by_id
next(self.run(q))
File "***/.pyenv/versions/3.6.9/lib/python3.6/site-packages/ledgerautosync/ledgerwrap.py", line 160, in run
universal_newlines=True).splitlines(),
File "***/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "***/.pyenv/versions/3.6.9/lib/python3.6/subprocess.py", line 438, in run
output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['ledger', '--args-only', '-f', '***/personal.ledger', 'csv', '-E', 'meta', 'ofxid=1506983S037.P4QYNELGXF']' returned non-zero exit status 20.
I installed dev source to have output date format handling.
I use ̀--input-date-format %d/%m/%Y` option in ledger, but this does not exists for ledger-autosync.
Do you have an idea for me ? Is there something I misunderstood ?
@etienne-monier I've never tried this, but you could try setting the environment variable LEDGER_DATE_FORMAT="%d/%m/%Y'.
Hi, This does not work.
I had forgotten to tell you I've got a .ledgerrcfile which contains:
--file ***/personal.ledger
--pedantic
--input-date-format %d/%m/%Y
--date-format %d/%m/%Y
It seems this is read when calling ledger-autosync file.ofxas I do not give the file. Instead, it reads the file specified by .ledgerrc.
Yes, that's right, ledger-autosync parses .ledgerrc, but only the --file argument. It would be pretty easy (I think) to use the --date-format argument in ledger-autosync to pass on as --date-format to ledger. @kevinjfoley wrote that code, I'm not sure the ins and outs of that.
Ok for the file.
The ledger --date-format is for output date format only. To specify the file format, I must use --input-date-format.
Similarly, @kevinjfoley 's implementation only permit to format the output of ledger-autosync. In his pull request, you told that was rare to use different date formatting, but that is not in France :D
I'll have a look at that, but I think for the moment to use a small script to toogle the file date format. I've got a PhD thesis to write :s
:) I see no reason why Kevin's implementation can't be extended to pass --input-date-format to ledger as well. In fact, it seems to me that if you want --date-format set you want --input-date-format set as well. But perhaps @kevinjfoley knows more.
I think it will require a bit of work since it will have to pass the parameter through to a completely different place (multiple place actually, one for each MetaLedger).
However I don't think it should be too difficult, I'll try to open a PR to address when I have some time this week.
I can take a look at it, I just wanted to check in to make sure that it made sense to you!
No problem, I don't mind looking either! But yeah I think the two changes will be largely unrelated other than sharing a parameter (though I only have a cursory knowledge of the code base).
it seems to me that if you want --date-format set you want --input-date-format set as well
This is probably true 99.99% of the time but I wouldn't be surprised if someone has a use case where it isn't true. Might be worth it to have --input-date-format as optional, and use date-format for when input-date-format isn't set.