hledger icon indicating copy to clipboard operation
hledger copied to clipboard

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

Open chrpinedo opened this issue 1 year ago • 6 comments

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

  • Any value of timeclock files are parsed as hours ("h"):
# file: time.timeclock
i 2022/08/01 13:53:51 task:example
o 2022/08/03 14:29:48

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

chrpinedo avatar Aug 04 '22 11:08 chrpinedo

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 ?

simonmichael avatar Aug 04 '22 14:08 simonmichael

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 !

chrpinedo avatar Aug 05 '22 07:08 chrpinedo

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"...

simonmichael avatar Aug 05 '22 08:08 simonmichael

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.

chrpinedo avatar Aug 05 '22 08:08 chrpinedo

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.

kiil avatar Aug 06 '22 00:08 kiil

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).

simonmichael avatar Aug 06 '22 03:08 simonmichael