Live Hours Nav
A small-business header that says whether the shop is open right now — computed in the shop's timezone, with overnight hours and split shifts handled.
- Category
- Components
- Added
- 2026-09-24
- Deps
- none
- Updated
- 2026-09-24
This is a viberdy Pro component
The live preview, the props panel and the write-up are open to everyone. The full source, the AI prompt and CLI install are part of Pro.
Est. 1998 — Walk-ins till 5
Cuts, shaves & hot towels
Props
"use client";
import { useEffect, useId, useMemo, useRef, useState, useSyncExternalStore } from "react";
/**
* A site header that knows whether the shop is open.
*
* THE SHOP'S CLOCK, NOT THE VISITOR'S. "Open now" is a statement about the
* business's wall clock. new Date().getHours() answers it for wherever the
* visitor happens to be, so a customer checking a London barber from New York
* is told it is shut all afternoon. Weekday and time are read through Intl in
* the business's own IANA zone, which also handles daylight saving for free.
*
* NEVER RENDER THE TIME ON THE SERVER. A statically generated page is built
* once and served for hours, so a server-rendered "Open now" is frozen at build
* time — and it is a guaranteed hydration mismatch. The clock is a
* useSyncExternalStore whose server snapshot is 0, shown as a placeholder of
* the same width, and the real value lands on mount.
// ---------------------------------------------------------------
// Full source available with a viberdy Pro subscription.
// https://viberdy.dev/pricing
// ---------------------------------------------------------------
}About this component
Opening hours are the single most common reason a customer phones a small business, and most sites bury them in a footer table that forces the reader to work out the day, the time and the answer themselves. This header does the arithmetic: a spec strip across the top states whether the shop is open, when it closes or next opens, and what time it is where the shop actually is. The last part is the one implementations get wrong. Reading new Date().getHours() computes the visitor's wall clock, so anyone outside the shop's timezone gets a confident, wrong answer; here the weekday and time come from Intl in the business's own IANA zone, which also carries daylight-saving changes. Hours are modelled as a week rather than seven separate days, so a bar open until 02:00 on Friday is correctly open early on Saturday, split lunch and dinner shifts parse naturally, and back-to-back ranges report the real closing time. The status never renders on the server — a statically built page would freeze it — and the header responds to its own width through container queries rather than to the viewport.
Curator’s note
Every 'open now' badge I have seen in the wild computes the visitor's clock, not the shop's. It is right for exactly the customers who could walk past and check.
Pairs well with
Matched on shared tags and category — the entries most likely to be used alongside this one.
Index Overlay Menu
componentsA full-screen menu set like a printed index — numbered entries in heavy type, and a treated photo plate that wipes in the direction you travel.
Thumb Action Dock
componentsA phone bottom bar with Call, Directions and Book — that appears once the hero's CTA has gone, and steps aside for the footer, a focused field and the keyboard.
Priority Plus Nav
componentsA nav that measures itself and collapses what does not fit into a More menu — ghost-row measurement, no breakpoints, no flicker loop.