Numbers, tables and totals / Time and duration log
A time log where start, end and duration are all checkable
Rows of start time, end time and elapsed duration, with a total, used on timesheets, service reports and anything billed by the hour.
Why this block is harder than it looks
Times and durations look like the same kind of value and are not, and printing them in the same format is the single thing that makes a time log unreadable. 09:00 as a start time and 09:00 as a duration are nine hours apart in meaning. On top of that, a shift crossing midnight produces an end time earlier than the start, which is correct and looks like an error, and durations sum in base sixty, so a column of them cannot be added by anyone reading down the page unless the format helps.
The decisions that make it work
Reasons rather than a description of the code. Each of these is a choice that has a wrong answer, and the wrong answer is usually the default.
- Format durations differently from times. 7h 30m for a duration and 09:00 for a clock time removes the ambiguity in one change, and it is worth the extra characters.
- Mark a shift that crosses midnight on the row, with the end date or a small marker, so an end time earlier than the start reads as intended rather than as a typing error.
- Right-align the duration column and use tabular figures, so the hours line up even when one entry is a single digit.
- Total in the same format as the rows, and give the total in decimal hours as well where the document is used for billing, because that is the number that gets multiplied.
- Keep the date column narrow and repeat the date only when it changes, so a week of entries reads as a week rather than as thirty-five identical strings.
- Give each day's group break-inside: avoid where the entries are grouped by day, so a day is never split across a page.
The fragment
Markup and the CSS it needs, and nothing else. It expects a document that already has a page rule and a base stylesheet, so paste it into one rather than opening it on its own.
<table class="timelog">
<thead>
<tr><th>Date</th><th>Start</th><th>End</th><th class="n">Duration</th></tr>
</thead>
<tbody>
<tr><td>Mon 09 Mar</td><td class="t">08:30</td><td class="t">17:00</td>
<td class="n">8h 30m</td></tr>
<tr><td></td><td class="t">22:00</td><td class="t">06:00 <i>+1</i></td>
<td class="n">8h 00m</td></tr>
</tbody>
<tfoot>
<tr><td colspan="3">Total</td><td class="n">16h 30m (16.50)</td></tr>
</tfoot>
</table>
<style>
.timelog { width: 100%; border-collapse: collapse; font-size: 9pt; table-layout: fixed; }
.timelog th, .timelog td { padding: 3pt 4pt; }
.timelog .t {
font-variant-numeric: tabular-nums; /* clock times */
white-space: nowrap;
}
.timelog .t i { font-style: normal; font-size: 7pt; color: #777; }
.timelog .n {
text-align: right;
white-space: nowrap;
font-variant-numeric: tabular-nums; /* durations, formatted differently */
}
.timelog tfoot td { border-top: 1pt solid currentColor; font-weight: 700; padding-top: 5pt; }
.timelog tbody tr { break-inside: avoid; }
</style>What breaks when it is built the obvious way
Printing durations as HH:MM, the same as the clock times. The column then looks like a third set of times, and anyone totalling it in their head adds it in base ten and gets the wrong answer. Formatting the duration differently costs three characters and removes the whole class of error.
How to prove it survived pagination
Render a week including one shift that crosses midnight and one entry under an hour. The overnight row should be visibly marked, the sub-hour row should still align, and the total should equal the durations added in base sixty rather than base ten.
Where it sits in a finished document
This page is one block. The document it belongs to has a page rule, a base stylesheet, a header and everything else around it, and repeating all of that here would make thirty pages that say the same thing. The weekly timesheet template is a complete file with this block already in it, so take that and change the fragment rather than assembling one from parts. The property doing most of the work here is covered on its own page, with the support caveats that belong there rather than here.
Frequently asked
Will this fragment work on its own?
Not as a whole document. It has no page rule, no margins and no base type, because those belong to the document rather than to the block, and duplicating them in every fragment would mean thirty copies to keep in step. Paste it into a template that already has them.
Why does it look right in a browser and wrong in the PDF?
Because a browser window is one continuous surface and a document is a stack of fixed rectangles. Nothing in a scrolling view exercises a page boundary, so every break rule in the fragment is inert until the content is paginated. Render the real thing with enough content to cross two or three boundaries, then look.
Do I need a special option on the render request for this?
No. Everything on this page is CSS and markup, which is your side of the boundary. What the render has to give you is a real page size with real margins, and after that the layout is decided by the stylesheet.
Other parts of a document
The blocks that sit next to this one, and one from the next group along so you are not sealed inside a single kind of problem.
A percentage column that reads as percentages, not as amounts
A column of rates, shares or variances, sitting next to columns of money and needing to be distinguishable from them at a glance.
This period against last period, side by side and comparable
The same set of figures for two periods, printed adjacent so the difference between them can be read without arithmetic.
A schedule of rates with units that stay attached to their prices
A price list keyed by activity and unit of measure, referred to from elsewhere in the document rather than totalled at the bottom.
A list of people present, with roles and space to sign
Names, roles and organisations of the people present at a meeting, inspection or signing, sometimes with a signature space each.
Weekly timesheet, as a complete file
The whole document with this block already in place, ready to copy and change.
font-variant-numeric in paged output
The property carrying the weight here, with its real support status.
Every part of a document
The full list, grouped by the kind of problem the block poses.
Paste the fragment into the playground inside a page rule and see what it does at a real page size. That is the only way any of this gets confirmed.