Seven-segment HH:MM:SS clock with a 12/24-hour toggle
Build the clock on a microwave-style LED display. It shows the current local time as HH:MM:SS, and every digit is drawn with seven light segments instead of text. A button switches the display between 24-hour and 12-hour time.
Each digit has seven segments named a to g:
aaaa
f b
f b
gggg
e c
e c
dddd
Light exactly these segments for each digit:
Digit Lit segments Digit Lit segments
0 a b c d e f 5 a c d f g
1 b c 6 a c d e f g
2 a b d e g 7 a b c
3 a b c d g 8 a b c d e f g
4 b c f g 9 a b c d f g
09, not 9). Separators between the pairs are up to you.role="img" and aria-label set to the digit it shows, for example aria-label="7".data-segment set to its name ("a" to "g"). A lit segment has data-lit="true". An unlit segment has data-lit="false" or no data-lit at all. Style lit and unlit segments however you like.new Date() on every update, and update at least once per second. Clear the timer when the clock is unmounted.00 to 23). Render a button labelled Switch to 12-hour. Clicking it switches to 12-hour time and changes its label to Switch to 24-hour. Clicking it again switches back.01 to 12, and the text AM (hours 0 to 11) or PM (hours 12 to 23) is shown next to the digits. In 24-hour time, no AM/PM text is shown.Local time 24-hour display 12-hour display
18:42:36 18:42:36 06:42:36 PM
00:15:00 00:15:00 12:15:00 AM
12:30:05 12:30:05 12:30:05 PM
09:07:41 09:07:41 09:07:41 AM
At 18:42:36, the first digit is 1, so it has aria-label="1" and only segments b and c have data-lit="true".
23:59:59, one second later is 00:00:00.12 in 12-hour time: 12:00:00 AM and 12:00:00 PM.The tests replace the browser clock (Date, setTimeout, setInterval, requestAnimationFrame and performance.now) with a fake clock set to a fixed time, and move it forward by hand. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
role="img" elements that contain [data-segment] elements, in reading order, each with exactly seven segments.data-lit="true" in each digit matches the table above, and each digit’s aria-label is the digit shown.AM or PM only in 12-hour time.