Skip to content

geochron: clock_format "12h" overflows the sidebar on 128x32 — the AM/PM suffix isn't measured #458

Description

@ChuckBuilds

Summary

Setting clock_format: "12h" makes geochron's sidebar clock run 3px past the right edge on a 128x32 panel. show_seconds already defaults to true, so flipping that one setting is enough to trigger it — no unusual configuration needed.

Reproduction

Plugin v1.0.4, LEDMatrix v3.3.0-4-g0730d952:

cd ~/LEDMatrix
python3 scripts/check_plugin.py -p geochron -d ~/LEDMatrix/plugin-repos \
  --golden-dir /tmp/nogolden -c '{"clock_format": "12h"}'
[FAIL]  128x32  geochron overflow bbox=(128, 1, 131, 21)
[PASS]  64x32 / 64x64 / 96x48 / 128x64 / 256x32 / 128x96 / 256x128

Isolation

config 128x32
default (24h, show_seconds: true) pass
clock_format: "12h" FAIL
clock_format: "12h", show_seconds: true (explicit) FAIL
clock_format: "12h", show_seconds: false pass
clock_format: "24h", show_seconds: true pass
clock_format: "12h", show_digital_clock: false pass
graticule_step_deg: 15 pass

So it is exactly 12h + seconds, and only at 128x32.

Cause

geochron_renderer.py:185-195:

def format_clock(dt, fmt="24h", show_seconds=True):
    if fmt == "12h":
        hour = dt.hour % 12 or 12
        ampm = "AM" if dt.hour < 12 else "PM"
        if show_seconds:
            return f"{hour}:{dt.minute:02d}:{dt.second:02d}{ampm}"
        return f"{hour}:{dt.minute:02d}{ampm}"
    if show_seconds:
        return f"{dt.hour:02d}:{dt.minute:02d}:{dt.second:02d}"
    return f"{dt.hour:02d}:{dt.minute:02d}"

23:47:52 is 8 characters; 11:47:52PM is 10. In wide_sidebar mode the rows are drawn from sidebar_x + 2 with no measurement against the sidebar width, so the two extra characters spill over the panel edge.

The surrounding code shows the author was already width-conscious about this sidebar:

# The sidebar is narrow (~32px), so labels like "UTC"/"LCL" and full
# ISO dates don't fit a 4px-wide pixel font. Row order conveys
# meaning instead: ...

and the featured-city row explicitly drops seconds to save space:

time_str = format_clock(featured_city["local_dt"], clock_format, False)

The main clock rows just didn't get the same treatment for the 12h case.

Suggested fix

Any of:

  • Drop seconds automatically when clock_format == "12h" and the sidebar is narrow, the way the featured-city row already does.
  • Use a single-letter suffix (11:47:52p) or drop the AM/PM marker when it doesn't fit — in a sidebar this narrow the meridiem is arguably the least valuable character.
  • Measure the formatted row against L["sidebar_w"] and shrink or trim, so any future format change is caught by construction.

How it was found

A schema-driven sweep that renders each plugin once per enum value / boolean combination / numeric bound derived from its own config_schema. Across 13 plugins and ~100 config variants this and one already-reported 7-segment-clock case were the only failures, so the sweep is quiet enough to be worth running in CI.

Environment

256x64 rig, LEDMatrix v3.3.0-4-g0730d952, geochron 1.0.4.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions