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

every N days periodic txn begins on wrong day #750

Closed
Xitian9 opened this Issue May 4, 2018 · 8 comments

Comments

Projects
None yet
2 participants
@Xitian9
Contributor

Xitian9 commented May 4, 2018

When forecasting, periodic transactions are always scheduled to start on the first day after the last posting, and then repeat after the appropriate interval. Is there a specific reason for this design choice? If an explicit start date is given for a periodic transaction, it would seem to make sense to honour the dates given.

For example, if I pay my rent every other Thursday, I would enter a periodic transaction

~ biweekly from 2018-05-03
     expenses:rent    1
     assets:bank     -1

I would expect forecast transactions to happen on 2018-05-03, 2018-05-17, etc.. As it is, hledger forecasts that I will pay rent the day after the last transaction, and every two weeks after that, regardless of whether it aligns with the ‘every other Thursday’ specification.

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael May 4, 2018

Owner

I'm a little unclear on the problem, so I'll wait - can you show an example ?

Owner

simonmichael commented May 4, 2018

I'm a little unclear on the problem, so I'll wait - can you show an example ?

@simonmichael simonmichael added the journal label May 4, 2018

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael May 4, 2018

Owner

I mean, a more complete example - eg what other existing transactions do you have in the journal above ?

Owner

simonmichael commented May 4, 2018

I mean, a more complete example - eg what other existing transactions do you have in the journal above ?

@Xitian9

This comment has been minimized.

Show comment
Hide comment
@Xitian9

Xitian9 May 4, 2018

Contributor

Use the following journal file:

~ every 14 days from 2018-05-02
    expenses:rent   1
    assets:bank    -1

2018/05/03  Spend money
    expenses:other   2
    assets:bank     -2

Then run hledger register --forecast. The forecast transactions are on the following days; the behaviour I would expect is in brackets:

  1. 2018-05-04 (2018-05-16)
  2. 2018-05-18 (2018-05-30)
  3. 2018-06-01 (2018-06-13)
Contributor

Xitian9 commented May 4, 2018

Use the following journal file:

~ every 14 days from 2018-05-02
    expenses:rent   1
    assets:bank    -1

2018/05/03  Spend money
    expenses:other   2
    assets:bank     -2

Then run hledger register --forecast. The forecast transactions are on the following days; the behaviour I would expect is in brackets:

  1. 2018-05-04 (2018-05-16)
  2. 2018-05-18 (2018-05-30)
  3. 2018-06-01 (2018-06-13)
@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael May 4, 2018

Owner

Ok, I get it. Yes I agree, it should start on the first instance of the periodic pattern after the last date - which is not always the very next day.

Owner

simonmichael commented May 4, 2018

Ok, I get it. Yes I agree, it should start on the first instance of the periodic pattern after the last date - which is not always the very next day.

@simonmichael simonmichael added the A BUG label May 4, 2018

@Xitian9

This comment has been minimized.

Show comment
Hide comment
@Xitian9

Xitian9 May 4, 2018

Contributor

Interestingly, correct behaviour is observed replacing the periodic pattern with any of the following:

  • ~ biweekly from 2018-04-30
  • ~ every 2 weeks from 2018-04-30
  • ~ monthly from 2018-05-01
  • ~ every Thursday

It seems to appear only when using the every N days pattern.

Contributor

Xitian9 commented May 4, 2018

Interestingly, correct behaviour is observed replacing the periodic pattern with any of the following:

  • ~ biweekly from 2018-04-30
  • ~ every 2 weeks from 2018-04-30
  • ~ monthly from 2018-05-01
  • ~ every Thursday

It seems to appear only when using the every N days pattern.

@Xitian9

This comment has been minimized.

Show comment
Hide comment
@Xitian9

Xitian9 May 4, 2018

Contributor

The issue seems to lie here. The root of the problem seems to be that intersecting the period expression span with the forecast span forgets the start date of the period expression. This is not a problem for any interval aside from Days, but results in this issue.

A solution would seem to be to have splitSpan _ (DateSpan (Just _) Nothing) return an infinite list (instead of the current singleton), and then take only those intervals which have non-zero intersection with the forecast span. However, I don't know if other parts of the program rely on existing behaviour.

Contributor

Xitian9 commented May 4, 2018

The issue seems to lie here. The root of the problem seems to be that intersecting the period expression span with the forecast span forgets the start date of the period expression. This is not a problem for any interval aside from Days, but results in this issue.

A solution would seem to be to have splitSpan _ (DateSpan (Just _) Nothing) return an infinite list (instead of the current singleton), and then take only those intervals which have non-zero intersection with the forecast span. However, I don't know if other parts of the program rely on existing behaviour.

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael May 4, 2018

Owner

I haven't totally grokked this yet but if you feel like making a pull request and make test still passes, I'd be happy to merge it.

Owner

simonmichael commented May 4, 2018

I haven't totally grokked this yet but if you feel like making a pull request and make test still passes, I'd be happy to merge it.

@simonmichael simonmichael changed the title from Better forecasting precision to every N days periodic txn begins on wrong day May 5, 2018

@simonmichael

This comment has been minimized.

Show comment
Hide comment
@simonmichael

simonmichael May 10, 2018

Owner

Looks great. Thank you!

Owner

simonmichael commented May 10, 2018

Looks great. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment