simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
2.87k stars 306 forks source link

posting date inference rules complicated/inconsistent ? #779

Open simonmichael opened 6 years ago

simonmichael commented 6 years ago

http://hledger.org/journal.html#posting-dates Cc'ing from mail list:

On May 18, 2018, at 2:12 AM, Francesco Ariis wrote:

I do not use them, rules for inferring the year seem too convoluted for their own good; if nobody uses this, I say drop'em.

That's interesting about convoluted rules, I didn't think they were. Here's my understanding of year inference in posting dates.

I always think "acquire date information from the nearest appropriate source".

A transaction can have 1-2 dates specified, which I'll call txndate1 and txndate2, and a posting can have 0-2, which I'll call postingdate1 and postingdate2. Here's a sample transaction you could test along with:

2018/1/1=2019/1/2 ; txndate1 and txndate2 are specified
  (a)  1  ; ...postingdates go here...

Then:

; [2/1]
a postingdate1, acquires its year from txndate1

; [2/1=2019/2/2]
the postingdate1 acquires its year from txndate1

; [2018/2/1=2/2]
the postingdate2 acquires its year from postingdate1

; [2/1=2/2]
the postingdate1 acquires from txndate1, the postingdate2 acquires from postingdate1

; [=2/2]
just a postingdate2, acquires its year from postingdate1 (which in this case is acquired from txndate1). I had to test this one. I can see how one could guess it would acquire from txndate2, but the "nearest appropriate source" is postingdate1.

When using tag syntax, the rules are almost the same, but not quite! date2: prefers to acquire from txndate2, eg:

2018/1/1=2019/1/2
  (bracketedsyntax)  1  ; [2/1=2/2]
  (tagsyntax)        1  ; date:2/1, date:2/2

$ hledger -f- reg
2018/02/01                      (bracketedsyntax)                1             1
                                (tagsyntax)                      1             2
$ hledger -f- reg --date2
2018/02/02                      (bracketedsyntax)                1             1
2019/01/02                      (tagsyntax)                      1             2

Perhaps this inconsistency should be fixed ?

And yes, I can see there is room for confusion.

But of course,

; [2018/5/18]
; [=2018/5/19]
; [2018/5/18=2018/5/19]
; date:2018/5/18, date2:2018/5/19

if you always write the year there are no rules involved.

awjchen commented 6 years ago

When using tag syntax, the rules are almost the same, but not quite! date2: prefers to acquire from txndate2, eg: ...

This distinction surprised me! I had assumed that date tags and bracketed dates were just two syntaxes for the same underlying concept, and that they would be indistinguishable after the parsing phase.

simonmichael commented 6 years ago

Me too. I think we should make date2: acquire from postingdate1 for consistency.