Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid date format when reading ledger file #97

Open
etienne-monier opened this issue Mar 8, 2020 · 8 comments
Open

Invalid date format when reading ledger file #97

etienne-monier opened this issue Mar 8, 2020 · 8 comments

Comments

@etienne-monier
Copy link

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 ?

@egh
Copy link
Owner

egh commented Mar 8, 2020

@etienne-monier I've never tried this, but you could try setting the environment variable LEDGER_DATE_FORMAT="%d/%m/%Y'.

@etienne-monier
Copy link
Author

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.

@egh
Copy link
Owner

egh commented Mar 9, 2020

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.

@etienne-monier
Copy link
Author

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

@egh
Copy link
Owner

egh commented Mar 11, 2020

:) 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.

@kevinjfoley
Copy link
Contributor

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.

@egh
Copy link
Owner

egh commented Mar 11, 2020

I can take a look at it, I just wanted to check in to make sure that it made sense to you!

@kevinjfoley
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants