Analog clock with rotating hands and a digital time readout
Build a wall clock for a train-station departures screen. It has a round face with hour, minute and second hands that show the current local time and move once per second. Below the face, a digital readout shows the same time as text.
aria-label="Hour hand", aria-label="Minute hand" and aria-label="Second hand".transform that contains rotate(<angle>deg). In React, use style={{ transform: ... }}. In vanilla JS, set el.style.transform. With SVG, the transform="rotate(<angle> cx cy)" attribute also works.seconds × 6minutes × 6 + seconds × 0.1(hours % 12) × 30 + minutes × 0.5 + seconds / 120h:mm:ss AM or h:mm:ss PM. Don’t pad the hour with a zero. Use 12 for both midnight and noon. Examples: 9:05:07 AM, 12:00:00 PM, 12:30:15 AM.new Date() on every update, and update at least once per second. Counting ticks yourself drifts from the real time.Time Readout Hour hand Minute hand Second hand
10:08:30 10:08:30 AM 304.25deg 51deg 180deg
15:45:00 3:45:00 PM 112.5deg 270deg 0deg
00:05:09 12:05:09 AM 2.575deg 30.9deg 54deg
12:00:00 PM, and all three hands point straight up.The tests replace the browser clock (Date, setTimeout, setInterval, requestAnimationFrame and performance.now) with a fake clock set to a fixed time. They move it forward by hand, so you can use any of those APIs. You don’t need test ids, specific class names, or an exact HTML structure. They check that:
Hour hand, Minute hand and Second hand.transform (or SVG transform attribute) contains rotate(<angle>deg) within 1° of the formula above. Angles are compared modulo 360.10:08:30 AM, and it updates after each simulated second.Capitalization and extra spacing don’t matter.