invoice2data icon indicating copy to clipboard operation
invoice2data copied to clipboard

Date format in JSON output is hard coded to %d/%m/%Y

Open wollanup opened this issue 6 years ago • 7 comments

https://github.com/invoice-x/invoice2data/blob/48006efe961584660414c432afbad1ef05a65b3c/src/invoice2data/output/to_json.py#L42

Date format is hard coded to french (maybe more) format day/month/year.

Could we add an options like date_formats_output or something to have a way to produce more standard format like %Y-%m-%d ?

I also noticed that only date field is handled, but we ignore fields prefixed with date to apply strftime on them

wollanup avatar Feb 21 '19 10:02 wollanup

Totally agree. Just do a PR to change it.

m3nu avatar Feb 21 '19 10:02 m3nu

@m3nu OK, I'm not familiar with Python yet but I'm on it ;)

Please just tell me if this approach looks fine to you :

def write_to_file(data, path, date_output_format='%d/%m/%Y'):

As we have path arg, I would add a new arg date_output_format in each write_to_file functions and pass it in call of output_module.write_to_file() from main.py

wollanup avatar Feb 21 '19 11:02 wollanup

Yeah. Could be good to add it as optional keyword argument. You want to keep the old default or make it an ISO format?

One small style note: When a string is for formatting, one would usually use double quotes. "%d-.."

m3nu avatar Feb 21 '19 11:02 m3nu

OK for double quoting ! Maybe we should keep previous format as default and override on demand to avoid BC ?

wollanup avatar Feb 21 '19 11:02 wollanup

Yes. Let's keep the old format.

m3nu avatar Feb 21 '19 11:02 m3nu

I'm almost good with code and test, but I introduced a change... You could call it a Breaking Change or a Bug Fix, you decide ;)

If we consider output JSON of free_fiber.pdf file, we had :

{
  "date": "02/07/2015",
  "date_due": "2015-07-05 00:00:00"
}

Now, we have this output (without --output-date-format option) :

{
  "date": "02/07/2015",
  "date_due": "05/07/2015"
}

And (with --output-date-format %Y-%m-%d)

{
  "date": "2015-07-02",
  "date_due": "2015-07-05"
}

It sounds better to me because we have only one format for dates. PR coming soon...

wollanup avatar Feb 21 '19 15:02 wollanup

Last option looks best, I think. I'll write a note about it in the release log. Better to fix this now then wait even longer.

I assume most people use it as library anyways, so they get a direct datetime object.

m3nu avatar Feb 21 '19 15:02 m3nu

Fixed by 212

bosd avatar Feb 06 '23 12:02 bosd