Files
berlin/README.md

3.4 KiB
Raw Permalink Blame History

Berlin Clock (Mengenlehreuhr)

A React + TypeScript application that implements the Berlin Clock (also known as the Mengenlehreuhr), a system invented in Berlin in 1975 to represent the time using coloured lamps.

Features

  • Real-time clock that automatically advances every second using the system time.
  • Converter mode uncheck the "Use system time" checkbox to switch to manual time input. The digital time display becomes editable, letting you set any time and immediately see its BerlinClock representation.
  • Full Berlin Clock layout:
    • Seconds lamp (top, round) blinks yellow every second.
    • Fivehour row four red lamps, each representing 5 hours.
    • Onehour row four red lamps, each representing 1 hour.
    • Fiveminute row eleven lamps, each representing 5 minutes. Every third lamp is red to mark quarter hours; the remaining lamps are yellow.
    • Oneminute row four yellow lamps, each representing 1 minute.

Technologies

Getting Started

Prerequisites

  • Node.js (version 18 or later recommended)
  • npm, yarn, or pnpm

Installation

# Clone the repository
git clone <repository-url>
cd <repository-folder>

# Install dependencies
npm install

Running the Development Server

npm run dev

Open http://localhost:5173 in your browser to see the application.

Building for Production

npm run build

The output will be placed in the dist directory.

Running Tests

# Unit tests (Vitest)
npm test

# Endtoend tests (Cypress)
npx cypress run

# Open Cypress test runner
npx cypress open

Usage

When the application starts, the Berlin Clock shows the current system time (the "Use system time" checkbox is checked).

  • System clock mode the digital display shows the current time and is readonly. The Berlin clock updates every second.
  • Manual converter mode uncheck "Use system time". The digital time input becomes editable. Type a new time (hh:mm:ss) or use the browsers native date/time picker (if available). As you change the value, the Berlin Clock immediately reflects the entered time.

The Berlin Clock layout is readonly; it always shows the time represented by the digital input.

Project Structure

src/
├── App.tsx               Main application component
├── components/
│   ├── Lamp.tsx          Single lamp with state and border radius logic
│   └── LampLine.tsx      Row of lamps (used for fivehour, onehour, etc.)
├── containers/
│   ├── BerlinClock.tsx   Visual representation of the Berlin clock
│   ├── DigitalClock.tsx  Input field for digital time
│   └── TimeConverter.tsx Orchestrates clock switching and time sync
├── hooks/
│   └── useCurrentTime.ts Hook to manage current time state
├── types/
│   └── index.ts          Type definitions (`LampState`, `BerlinClock`)
├── utils/
│   └── index.ts          Conversion functions between Date and Berlin Clock
└── __tests__/            Unit tests corresponding to the source files