tgrosinger / md-advanced-tables

A text editor independent library to enable formatting and Excel-style navigation, and spreadsheet formulas to Markdown tables.
MIT License
149 stars 30 forks source link

Feature Request: Support addition of time (hh:mm) column #45

Closed ebdavison closed 1 year ago

ebdavison commented 2 years ago

With a table that contains hours and minutes in a columns, e.g.

| what      | from  | to    | total |
| --------- | ----- | ----- | ----- |
| first     | 18:30 | 19:00 | 0:30  |
| second    | 09:05 | 09:15 | 0:10  |
| third     | 12:30 | 12:45 | 0:15  |
| **total** |       |       | 0:55  | 

It would be great if we could get: a) calculate the total column by subtracting to - from and show it in total b) to add up the total column to show in the last **total** row

ebdavison commented 2 years ago

Right now, as it is, the formula to add up the last column (<!-- TBLFM: @>$4=sum(@I..@-1) -->) results in 0 which seems only add the part before the : as you can see here:

| what      | from  | to    | total | h   | m   |
| --------- | ----- | ----- | ----- | --- | --- |
| first     | 18:30 | 19:00 | 0:30  | 0   | 30  |
| second    | 09:05 | 09:15 | 0:10  | 0   | 10  |
| fourth    | 15:30 | 14:45 | 1:15  | 0   | 15  |
| third     | 12:30 | 12:45 | 0:15  | 0   | 15  |
| **total** |       |       | 1     | 0   | 70  |
<!-- TBLFM: @>$4=sum(@I..@-1) -->
rachelseabrook commented 1 year ago

I'd like to add my voice to the requests for time calculations. I'm using advanced tables for time planning: I have a list of tasks with estimated durations and columns for start time and stop time. At any point in the day I can enter 'now' into the stop time columns and recalculate start times for all of the subsequent tasks. I can shuffle tasks or add new ones and recalculate at any point. There's an additional column with a simple flag for fixed time tasks, i.e. appointments, and the start times of these don't get moved. I currently have two columns for each time, hours and minutes.

Example, taken shortly after 9:40, when two stop times had been entered and start times recalculated:

| task              | start h | start m | stop h | stop m | dur m | fix |
| ----------------- | ------- | ------- | ------ | ------ | ----- | --- |
| make tea          | ------- | 0       | 7      | 54     |       |     |
| morning pages     | 7       | 54      |        |        | 90    |     |
| plan day          | 9       | 24      | 9      | 40     | 20    |     |
| get dressed       | 9       | 40      |        |        | 15    |     |
| Teams mtg         | 10      | 0       |        |        | 30    |  1  |
| exercises         | 10      | 30      |        |        | 10    |     |
| breakfast         | 10      | 40      |        |        | 30    |     |
| Check Hub         | 11      | 10      |        |        | 20    |     |
| ==email Alex==    | 11      | 30      |        |        | 15    |     |
| Plan tutorials    | 11      | 45      |        |        | 90    |     |
<!-- TBLFM: @I$2..@>$2=if($7==1, $2, if(@-1$4>0, @-1$4, if((@-1$3+@-1$6)<60, @-1, if((@-1$3+@-1$6)<120, (@-1+1), if((@-1$3+@-1$6)<180, (@-1+2), if((@-1$3+@-1$6)<240, (@-1+4), 999)))))) -->
<!-- TBLFM: @I$3..@>$3=if($7==1, $3, if(@-1$4>0, @-1$5, if((@-1$3+@-1$6)<60, (@-1$3+@-1$6), if((@-1$3+@-1$6)<120, ((@-1$3+@-1$6)-60), if((@-1$3+@-1$6)<180, ((@-1$3+@-1$6)-120), if((@-1$3+@-1$6)<240, ((@-1$3+@-1$6)-180), 999)))))) -->
<!-- TBLFM: @I$2..@>$2=if(@+1$7!=1, $2, if((($2*60)+($3+$6))>((@+1$2*60)+@+1$3), 8080808, $2)) -->

Having time calculations would: 1 Reduce the number of columns and make the table more readable 2 Replace two - possibly all three - hideous formulae with one less hideous formula, and not require repeat evaluations because the hours and minutes get out of sync 3 Allow one touch entry of "now" times instead of manually typing or Template... Hours... Next column... Template... Minutes

Generally, time calculations would make this a lot sleeker and more usable, and then I could share it with the people who are requesting this functionality from Day Planner. (If Day Planner could then be adapted to read a table instead of a list of tasks... But that's another project)

tgrosinger commented 1 year ago

I think this is a duplicate of #31

nolda commented 1 year ago

Emacs' Org mode actually supports operations on durations and times in table cells, with flags T and U.