@leelaing/live-clock
v0.1.0
Published
Reusable timezone-aware live date and time utilities with an unstyled React clock.
Readme
@leelaing/live-clock
Reusable timezone-aware live date and time utilities with a React hook and an unstyled React clock component.
The package owns date/time behavior, not visual design. It does not ship CSS or depend on Tailwind, DaisyUI, Bootstrap, Material UI, Electron, Tauri, or application-specific styling.
Install
npm install @leelaing/live-clockReact consumers must provide React 18 or newer.
Core Utilities
import { formatDate, formatDateTime, formatTime } from '@leelaing/live-clock';
const now = new Date();
formatDate(now, {
locale: 'en-US',
timeZone: 'America/New_York',
dateFormat: 'long',
weekday: true
});
formatTime(now, {
locale: 'en-US',
timeZone: 'Europe/London',
timeFormat: '24h',
seconds: true,
timeZoneName: 'short'
});
formatDateTime(now, {
timeZone: 'Australia/Perth',
separator: '@'
});React Hook
import { useLiveClock } from '@leelaing/live-clock';
function HeaderClock() {
const clock = useLiveClock({
timeZone: 'America/Los_Angeles',
timeFormat: 'auto'
});
return <time dateTime={clock.iso}>{clock.dateTime}</time>;
}The hook returns structured data:
{
now,
timestamp,
iso,
date,
time,
dateTime,
timeZone,
timeZoneName
}Unstyled Component
import { LiveClock } from '@leelaing/live-clock';
<LiveClock
layout="inline"
timeZone="America/New_York"
timeFormat="12h"
timeZoneName="short"
/>Supported layouts:
inlinedate-toptime-topdate-onlytime-only
Stable selectors and attributes are exposed for consuming applications:
lee-live-clocklee-live-clock__datelee-live-clock__timelee-live-clock__separatorlee-live-clock__timezonedata-live-clockdata-layoutdata-time-formatdata-time-zone
No styles are attached to those selectors.
Development
npm install
npm startQuality Checks
npm run checknpm run check runs:
- TypeScript type checking
- ESLint
- Tests
- Production build
Standard Commands
| Command | Purpose |
| --- | --- |
| npm start | Build/watch during development |
| npm run dev | Alias for npm start |
| npm run build | Production build |
| npm test | Run tests once |
| npm run test:watch | Run tests in watch mode |
| npm run lint | Lint source |
| npm run typecheck | TypeScript validation |
| npm run format | Format files |
| npm run check | Run all validation |
| npm run clean | Remove generated output |
License
MIT
