hledger icon indicating copy to clipboard operation
hledger copied to clipboard

csv rules: convert to ISO date format when setting posting dates

Open simonmichael opened this issue 2 years ago • 1 comments

In #hledger it was noted that you can't easily generate posting date tags if your CSV dates are not already in ISO format, because posting date tags require ISO dates (Simple Dates) and there's currently no way to interpolate dates in anything but their original textual format.

Idea 1 we came to was:

"Within transaction or posting comment rules, there is a special interpolation syntax: %ISO:FIELD. This is like %FIELD, except that if FIELD's value can be parsed as a date (using the date-format rule if any), it will be interpolated in ISO format (also localised to your time zone when appropriate)." This requires parsing and localising the date, just like but separately from the main date/date2 fields (because you may not want to call this date field "date" or "date2").

Idea 2 might be cleaner:

Add a dedicated hledger field name for setting posting dates: postingdateN. This would parse its assigned value as a date and then add it as a date:ISODATE tag to posting N. It would parse using the same date-format used for the transaction date. When given an unparseable value, it raises an error I guess. There would be no special support for setting the date2: tag.

simonmichael avatar Jan 13 '23 05:01 simonmichael

Unfinished WIP, help welcome: https://github.com/simonmichael/hledger/compare/csv-iso-dates

simonmichael avatar Apr 28 '23 03:04 simonmichael