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.94k stars 316 forks source link

inconsistent parsing of timeclock and timedot files complicates the use of a time budget #1908

Open chrpinedo opened 2 years ago

chrpinedo commented 2 years ago

Inconsistent parsing of timeclock and timedot files complicates the use of a budget.

i 2022/08/04 13:53:51 task:example o 2022/08/04 14:29:48

$ hledger -f time.timeclock print 2022-08-01 * 13:53-23:59 (task:example) 10.10h

2022-08-02 * 00:00-23:59 (task:example) 24.00h

2022-08-03 * 00:00-14:29 (task:example) 14.50h

2022-08-04 * 13:53-14:29 (task:example) 0.60h


- Any value of timedot files are parsed as numbers without "h" character:

file: time.timeclock

2022/08/01 task:example 10.1h

2022/08/02 task:example 1d

2022/08/03 task:example 14.5h

2022/08/04 * task:example ...

hledger -f time.timedot print
2022-08-01 * (task:example) 10.10

2022-08-02 * (task:example) 24.00

2022-08-03 * (task:example) 14.50

2022-08-04 (task:example) 0.75


So, If I want to use a budget file, I have to take into account if I am comparing with a timedot file (to define the budget values without "h") or a timeclock file (to define the budget values with "h").

file: budget.journal

~ weekly (task:example) 2h

$ # bad: $ hledger -f time.timedot -f time.timeclock -f budget.journal bal -W --budget Budget performance in 2022-08-01W31:

          ||      2022-08-01W31 

==============++==================== task:example || 49.35, 49.20h [2h] --------------++-------------------- || 49.35, 49.20h [2h]

$ # bad: $ hledger -f time.timedot -f budget.journal bal -W --budget Budget performance in 2022-08-01W31:

          || 2022-08-01W31 

==============++=============== task:example || 49.35 [2h] --------------++--------------- || 49.35 [2h]

$ # good: $ hledger -f time.timeclock -f budget.journal bal -W --budget Budget performance in 2022-08-01W31:

          ||        2022-08-01W31 

==============++====================== task:example || 49.20h [2460% of 2h] --------------++---------------------- || 49.20h [2460% of 2h]



Two possible solutions:
- Parse timedot values with "h" characters so timeclock, timedot and budget must use "h" values to get a valid budget report.
- Modify the budget report to be able to convert on-the-fly times with different values (s, m, h, d...)

hledger --version
hledger 1.25, linux-x86_64
simonmichael commented 2 years ago

I see that creates a bit of friction, if you are combining or switching between timedot and timeclock.

I don't remember if this works: in a parent journal file including the timedot file, declare h as a default commodity with D ?

chrpinedo commented 2 years ago

I combine timedot and timeclock, because taskwarrior integration (as referenced in https://hledger.org/time-planning.html) uses timeclock and for personal annotation is easier timedot.

I can confirm that the solution you suggested works right:

D 1000.0h

include time.timeclock
include time.timedot

All entries are parsed as hours:

$ hledger -f time.journal print                                         
2022-08-01 * 13:53-23:59
    (task:example)           10.1h

2022-08-01 *
    (task:example)           10.1h

2022-08-02 * 00:00-23:59
    (task:example)           24.0h

2022-08-02 *
    (task:example)           24.0h

2022-08-03 * 00:00-14:29
    (task:example)           14.5h

2022-08-03 *
    (task:example)           14.5h

2022-08-04 * 13:53-14:29
    (task:example)            0.6h

2022-08-04 * *
    (task:example)           0.75h

And the budget report is formatted correctly if budget is defined with "hours":

$ hledger -f time.journal -f budget.journal bal -W --budget
Budget performance in 2022-08-01W31:

              ||       2022-08-01W31 
==============++=====================
 task:example || 98.6h [4928% of 2h] 
--------------++---------------------
              || 98.6h [4928% of 2h] 

Thanks @simonmichael !

simonmichael commented 2 years ago

I'll leave this open in case we want to do something more. We inherited timeclock format and its hard-coded units. For timedot format I just wanted to leave it open so you could use it to track "other things"...

chrpinedo commented 2 years ago

In fact, I think is is a good thing to leave he format of timedot files open, because it is suppose to be quickly editable by humans. However, this flexibility can lead to other issues...

In any case, just for this issue, your workaround solves it.

kiil commented 2 years ago

For me, setting the default is not working since I have not set commodity explicitly for my transactions. So not only will time get the h suffix, so will all my financial transactions

D 1000.0h
include t.timedot

2022-07-06 tjen penge
  assets:konto                  20
  revenues:folkets             -20
➤ hledger -ff reg fol                                                                         02:04
2022-07-06 tjen penge                     revenues:folkets                     -20.0h        -20.0h
2022-08-01                                ((revenues:folkets))                   0.5h        -19.5h
2022-08-06                                ((revenues:folkets))                   3.0h        -16.5h

And, as you can see this mixes time and financial transactions up.

So I think there should be a way of setting h specifically for timedot.

simonmichael commented 2 years ago

For me, setting the default is not working since I have not set commodity explicitly for my transactions. So not only will time get the h suffix, so will all my financial transactions

You don't have to put the D where your regular transactions are - put it in a separate included journal (which includes the timedot).