So I have everything I need:
#let dt = datetime(hour: 8, minute: 0, second: 0)
#let ad = duration(minutes: 30)
#let dt = dt+ad
#show table.cell.where(y: 0): strong
#table(columns:2, "Time", "Tasks", [#dt.display("[hour]:[minute]")-])
Only I’m struggling to get the loop going to have ranges like 8:00-8:30, 8:30-9:00 etc. - any suggestions for this final step?
I worked around this by combining typst code with a csv file generated in bash:
#show table.cell.where(y: 0): strong
#table(columns:(auto, 1fr), "Time", "Task", ..csv("t.csv").flatten())
{
for i in {0..26}; do
date --date "@$(($(date --date 08:00 +%s)+1800*i))" +%R,
done
} > t.csv
but 100% native Typst solution would also be possible (somehow)
Here is a solution that loops over an array of hours and uses the duration ad to get a time range. Is this what you were looking for?
#let hours = range(8, 12)
#let ad = duration(minutes: 30)
#let date-format = "[hour]:[minute]"
#let cells = hours.enumerate().map(((i, hour)) => {
let t0 = datetime(hour: hour, minute: 0, second: 0)
let t1 = t0 + ad
table.cell(x: 0, y: i+1)[#t0.display(date-format)-#t1.display(date-format)]
})
#show table.cell.where(y: 0): strong
#table(columns: 2, "Time", "Tasks", ..cells)
Since the time ranges occupy all the cells with x = 0, additional arguments of the table will automatically be put into the “Tasks” column. The resulting table looks like this
1 Like