KOS Time Model - System time management with real-time synchronization and timezone control.

This singleton model provides centralized control over system time, date, and timezone settings with automatic event propagation when changes occur. Essential for applications that need to synchronize time-based operations, schedule events, or maintain consistent timestamps across the system.

Key Features

  • System Time Control - Update system hours, minutes, and seconds programmatically
  • Date Management - Set system date including month, day, and year
  • Timezone Handling - Change and track timezone with automatic updates
  • Real-time Events - Automatic notifications when time, date, or timezone changes
  • EventBus Integration - Publishes changes to internal EventBus for UI updates
  • WebSocket Sync - Changes propagate across all connected clients

Topic-Based Reactivity

The model listens to three KOS topics for time synchronization:

  • /kos/time/time - Fired when system time changes (hour/minute/second)
  • /kos/time/day - Fired when the date changes (day rollover or manual change)
  • /kos/time/timezone - Fired when timezone is updated

Additionally, the model publishes to internal EventBus topics:

  • TIME_CHANGE - For UI components to react to time updates
  • DAY_CHANGE - For date-dependent UI updates
  • TIMEZONE_CHANGE - For timezone-aware components

Common Use Cases

  • System Clock Management - Synchronize device time with server time
  • Scheduled Operations - Trigger events based on time changes
  • Multi-timezone Support - Handle devices in different time zones
  • Time-based UI Updates - Keep clocks and calendars synchronized
  • Audit Logging - Ensure consistent timestamps across the system
  • Day Rollover Handling - Reset daily counters or refresh data

Example: Basic Usage

const timeModel = KosTime.instance().build();

// Update system time and date
await timeModel.updateSystemTime({ hour: 15, min: 45, sec: 30 });
await timeModel.updateSystemDate({ month: 3, day: 15, year: 2024 });
await timeModel.updateSystemTimezone('America/New_York');

Use Declared Type

See

  • TimeBean - Time value structure (hour, minute, second)
  • DateBean - Date value structure (month, day, year)
  • KosTimeOptions - Configuration options for time model
interface KosTimeModel {
    updateSystemTime(time): Promise<void>;
    updateSystemDate(date): Promise<void>;
    updateSystemTimezone(timezone): Promise<void>;
}

Methods

  • Updates the system clock to the provided time.

    Parameters

    • time: TimeBean

      The time to set the system time to

    Returns Promise<void>

  • Updates the system clock to the provided date.

    Parameters

    • date: DateBean

      The date to set the system date to

    Returns Promise<void>

  • Updates the system clock to the provided timezone.

    Parameters

    • timezone: string

      The timezone to set the system timezone to

    Returns Promise<void>