Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@uplink-protocol/calendar-controller

jmkcoder658MIT0.3.0TypeScript support: included

Flexible calendar and time picker API supporting both calendar, date-picker, and time-picker integrations for any JavaScript framework or library

date-picker, time-picker, controller, validation, multi-step, wizard, react, calendar, time, datetime, uplink-protocol, i18n, typescript, javascript, web

readme

Calendar & Time Controller

A flexible calendar and time picker API supporting both calendar and time selection integrations for any JavaScript framework or library.

Latest Release (v0.2.3): Added comprehensive Time Controller with full time picker functionality alongside the existing Calendar Controller.

Features

Calendar Controller

  • Multiple view modes (day, month, and year views)
  • Date selection (single date and date range)
  • Year range navigation for efficient date picking
  • Disabled weekdays - Disable specific days of the week across all calendar views
  • Date constraints (min/max dates, disabled specific dates)
  • Internationalization support with locale-specific date formats
  • Flexible configuration options
  • Service-oriented architecture
  • Framework agnostic

Time Controller ✨ NEW

  • Time selection (single time and time range)
  • 12/24 hour format support
  • Precision control (hours, minutes, seconds, milliseconds)
  • Time navigation with keyboard support
  • Time constraints and validation
  • Accessibility features with focus management
  • Locale-aware time formatting
  • Reactive state bindings
  • Complete service-oriented architecture

Usage

Calendar Controller

import { CalendarController } from '@uplink-protocol/calendar-controller';

// Create a new calendar controller
const calendar = CalendarController({
  firstDayOfWeek: 1, // Monday
  dateFormat: 'MM/DD/YYYY',
  initialSelectedDate: new Date(),
  disabledDaysOfWeek: [0, 6] // Disable weekends
});

// Use the calendar API for date selection
calendar.methods.selectDate(2025, 4, 15);

// Work with different view modes
const days = calendar.bindings.calendarDays.get(); // Day view
const months = calendar.bindings.calendarMonths.get(); // Month view
const years = calendar.bindings.calendarYears.get(); // Year view

// Navigate between view modes
calendar.methods.selectMonth(3, 2025); // Select April 2025 in month view
calendar.methods.selectYear(2026); // Select 2026 in year view

// Navigate year ranges
calendar.methods.nextYearRange(); // Move to next decade
calendar.methods.prevYearRange(); // Move to previous decade

// Manage disabled weekdays dynamically
calendar.methods.setDisabledDaysOfWeek([0, 6]); // Disable weekends
calendar.methods.addDisabledDayOfWeek(1); // Also disable Monday
calendar.methods.removeDisabledDayOfWeek(0); // Re-enable Sunday

Time Controller ✨ NEW

import { TimeController } from '@uplink-protocol/calendar-controller';

// Create a new time controller
const timeController = TimeController({
  use12HourFormat: true,
  showSeconds: true,
  locale: 'en-US',
  minuteStep: 15
});

// Select a time
timeController.selectTime(9, 30, 0); // 9:30:00 AM

// Get reactive bindings
const selectedTime = timeController.bindings.selectedTime.get();
const formattedTime = timeController.methods.getFormattedTime();

// Navigate time
timeController.goToNextHour();
timeController.goToPreviousMinute();

// Time range selection
timeController.setRangeSelectionMode(true);
timeController.selectTime(9, 0);  // Start time
timeController.selectTime(17, 30); // End time

// Time constraints
timeController.setMinTime(new Date(2024, 0, 1, 9, 0));  // 9:00 AM
timeController.setMaxTime(new Date(2024, 0, 1, 17, 0)); // 5:00 PM
timeController.setDisabledHours([12, 13]); // Lunch break
const disabledDays = calendar.methods.getDisabledDaysOfWeek(); // Get current disabled days

Disabled Weekdays

Disable specific days of the week across all calendar views:

// Disable weekends for business applications
const businessCalendar = CalendarController({
  disabledDaysOfWeek: [0, 6] // 0 = Sunday, 6 = Saturday
});

// Disable specific business days
const customSchedule = CalendarController({
  disabledDaysOfWeek: [1, 3] // Monday and Wednesday
});

// Dynamic management
businessCalendar.methods.setDisabledDaysOfWeek([0, 5, 6]); // Weekends + Friday
businessCalendar.methods.addDisabledDayOfWeek(1); // Add Monday
businessCalendar.methods.removeDisabledDayOfWeek(5); // Remove Friday

See full documentation →

UI Integration

The examples provided showcase integration with:

  • Tailwind CSS - For responsive, utility-first styling
  • Font Awesome - For beautiful, scalable icons

Tailwind CSS Setup

<!-- Include Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
  tailwind.config = {
    theme: {
      extend: {
        colors: {
          primary: '#007bff',
          'primary-light': '#e6f2ff'
        }
      }
    }
  }
</script>

Font Awesome Setup

<!-- Include Font Awesome -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">

Architecture

This controller uses a service-oriented architecture where all the core functionality is delegated to specialized services:

  • CalendarService - Handles basic calendar operations like getting month names
  • DateSelectionService - Manages date selection logic
  • DateValidationService - Validates dates against constraints
  • DateFormattingService - Handles date formatting operations
  • ViewStateService - Manages UI state and bindings
  • EventManagerService - Manages event emission
  • NavigationService - Handles calendar navigation operations
  • ConstraintsService - Manages date constraints
  • CalendarGeneratorService - Generates calendar days
  • ConfigurationService - Manages calendar configuration options

Configuration Options

The following configuration options can be provided when creating a new calendar controller:

Option Type Default Description
minDate Date null Minimum selectable date
maxDate Date null Maximum selectable date
disabledDates Date[] [] Array of specific dates to disable
initialSelectedDate Date null Pre-selected date when calendar loads
firstDayOfWeek number 0 First day of week (0 = Sunday, 1 = Monday, etc.)
dateFormat string null Date format string (e.g., 'MM/DD/YYYY')
hideOtherMonthDays boolean false When true, hides days from previous and next months in the current month view

Example with hideOtherMonthDays

// Create a calendar that hides days from other months
const calendar = CalendarController({
  firstDayOfWeek: 1,
  dateFormat: 'MM/DD/YYYY',
  hideOtherMonthDays: true // Only show days from the current month
});

Internationalization

The calendar supports internationalization with the following features:

  • Localized Month Names: Month names are displayed according to the selected locale
  • Localized Weekday Names: Weekday names are displayed according to the selected locale
  • Locale-based Date Formatting: Dates can be formatted according to the locale conventions
  • RTL Support: Right-to-left languages are supported via the browser's localization

Configuration

// Internationalization options
const calendar = CalendarController({
  // Set locale (any valid BCP 47 language tag)
  locale: 'ja-JP', // Japanese

  // Optional date format options (Intl.DateTimeFormat options)
  dateFormatOptions: {
    year: 'numeric',
    month: 'long',
    day: 'numeric',
    weekday: 'short'
  }
});

Changing Locale Dynamically

// Change locale at runtime
calendar.methods.setLocale('ar-EG'); // Arabic (Egypt)

// Update date format options
calendar.methods.setDateFormatOptions({ 
  year: 'numeric',
  month: 'short',
  day: '2-digit'
});

Example

See the full example of internationalization usage in the i18n example.

Examples

The package includes comprehensive examples demonstrating various features and use cases:

Running Examples

All examples work directly in the browser without build tools:

# Clone the repository
git clone https://github.com/jmkcoder/uplink-protocol-calendar.git
cd uplink-protocol-calendar

# Open any example in your browser
# e.g., open examples/date-picker/index.html

Documentation

Comprehensive Guides

API Reference

v0.2.3 Improvements

  • Added comprehensive Time Controller with full time picker functionality
  • Complete service-oriented architecture for time operations
  • Full TypeScript support with comprehensive type definitions
  • 24 comprehensive tests ensuring reliability
  • Reactive bindings for real-time UI updates
  • Accessibility features with focus management

changelog

Changelog

All notable changes to the @uplink-protocol/calendar-controller package will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.3.0] - 2025-06-26

Added

  • TimeController - Complete Time Picker Solution

    • Introduced TimeControllerClass with comprehensive time selection functionality
    • Service-oriented architecture with 10 specialized time services:
      • TimeService - Core time operations and utilities
      • TimeFormattingService - Time formatting and localization
      • TimeSelectionService - Time selection logic and range handling
      • TimeViewStateService - Reactive bindings and UI state management
      • TimeEventManagerService - Event handling and emission
      • TimeNavigationService - Time navigation and focus management
      • TimeConstraintsService - Time validation and constraints
      • TimeGeneratorService - Time view generation
      • TimeConfigurationService - Configuration processing
      • TimeValidationService - Time validation logic
  • Comprehensive Time Features

    • Single time selection and time range selection modes
    • 12-hour and 24-hour format support with automatic AM/PM handling
    • Configurable time segments (hours, minutes, seconds, milliseconds)
    • Step-based time navigation (1, 5, 10, 15, 30 minute/second steps)
    • Advanced time constraints (min/max times, disabled times/hours/minutes/seconds)
    • Accessibility-focused segment navigation and keyboard support
  • Rich Time Configuration Options

    • Initial time selection and range selection
    • Customizable time format options and locale-specific formatting
    • Flexible time display options (show/hide seconds, milliseconds)
    • Comprehensive constraint system for business rules
    • Event-driven architecture with 6 time-specific events
  • Internationalization & Accessibility

    • Full internationalization support with Intl.DateTimeFormat integration
    • Locale-aware time formatting and cultural time preferences
    • Complete accessibility support with ARIA-compliant focus management
    • Keyboard navigation between time segments
  • Developer Experience

    • Factory function TimeController(options) for easy instantiation
    • TypeScript-first with comprehensive type definitions
    • Reactive bindings for modern UI frameworks (React, Vue, Angular)
    • Extensive method library (40+ time manipulation methods)
    • Comprehensive test coverage with 23 test suites

Enhanced

  • Package Exports

    • Added time controller exports to main index.ts
    • Updated TypeScript type definitions to include time types
    • Enhanced package keywords to include time-picker related terms
  • Documentation

    • Time controller capabilities documented in Examples/Time/
    • Advanced time examples and demos included
    • Comprehensive time controller guide available

[0.2.3] - 2025-06-26

Fixed

  • Intl-Based Locale Formatting
    • Fixed getLocaleDefaultFormatOptions() to use native Intl.DateTimeFormat for better locale detection
    • Enhanced cultural pattern recognition for date formatting preferences
    • Better support for unknown locales with automatic format option resolution
    • Maintains existing behavior while leveraging browser's native internationalization capabilities
    • Fixed all locale formatting default tests to pass with new Intl-based implementation
    • Ensured consistent behavior across different locale configurations

[0.2.2] - 2025-06-25

Added

  • Intelligent Locale-Based Date Formatting

    • Enhanced setLocale() method to automatically apply appropriate format defaults for different locales
    • Added getLocaleDefaultFormatOptions() private method with comprehensive locale-specific formatting rules
    • Supports 15+ locales with culturally appropriate formatting (e.g., long month names for European locales, numeric formatting for English/Asian locales)
    • Language-only locale fallbacks (e.g., "de" falls back to "de-DE" defaults)
    • Unknown locale fallback to "en-US" formatting
  • Enhanced Date Format Management

    • setDateFormatOptions() now accepts null to reset to locale-appropriate defaults
    • Improved persistence of custom format options across locale changes
    • Better integration between getFormattedDate() and locale-specific formatting
  • Comprehensive Test Coverage

    • Added 33 new tests in locale-formatting-defaults.test.ts
    • Validates correct format options for all supported locales
    • Tests real-world formatting output against browser Intl.DateTimeFormat
    • Verifies format option persistence and reset behavior
    • Edge case testing for unknown locales and case-insensitive handling

Enhanced

  • Localization Service Integration
    • Improved fallback logic in DateFormattingService when no format options are specified
    • Enhanced getFormattedDate() to use locale-default formatting when no explicit options are set
    • Better coordination between localization and date formatting services

Technical

  • Developer Experience
    • Comprehensive locale formatting validation tests
    • Improved TypeScript type definitions for date formatting
    • Enhanced documentation for internationalization features

[0.2.1] - 2025-06-02

Fixed

  • Example Fixes
    • Fixed function scope issue in disabled-weekdays example where button handlers were not accessible from global scope
    • Functions presetWeekends, presetWeekdays, applyDisabledDays, and clearDisabledDays are now properly exposed to window object
    • Resolved "ReferenceError: function is not defined" errors in example HTML onclick handlers

[0.2.0] - 2025-06-01

Added

  • Accessibility Improvements

    • Complete arrow key navigation support (up/down/left/right)
    • Advanced focus handling with moveFocus*() methods including:
      • moveFocusRight(), moveFocusLeft(), moveFocusUp(), moveFocusDown()
      • moveFocusToStartOfMonth(), moveFocusToEndOfMonth()
      • moveFocusToPreviousMonth(), moveFocusToNextMonth()
      • moveFocusToPreviousYear(), moveFocusToNextYear()
    • Screen reader support with accessible date labels and state descriptions
    • getAccessibleDateLabel() and getDateStateDescription() methods
    • selectFocusedDate() for keyboard-driven date selection
  • Service-Oriented Architecture

    • Modular service design for better maintainability
    • Calendar Generator Service for optimized calendar generation
    • Navigation Service with constraint validation
    • Accessibility Manager for comprehensive accessibility support
    • Calendar State Service for centralized state management
    • Configuration Service for streamlined configuration
    • Constraint Service for advanced date validation
  • Multi-View Support

    • Enhanced generateMonthView() with week number support
    • generateCalendarMonths() for year-level navigation
    • generateCalendarYears() for decade-level navigation
    • getWeekNumber() method for week number calculation
  • Developer Experience

    • Rich event system with comprehensive state change notifications
    • Batched binding updates for improved performance
    • updateAllBindings() with selective update options

Changed

  • Performance Optimizations

    • Batched binding updates using executeBatchedBindingUpdates()
    • On-demand calendar data generation
    • Improved memory management and state handling
  • Enhanced Method Signatures

    • selectDate() now supports multiple parameter formats
    • Improved constraint validation across navigation methods
    • Better error handling and edge case management

Fixed

  • Focus management during month/year navigation
  • Date constraint validation edge cases
  • Range selection state consistency
  • Disabled date handling in range selection
  • Binding updates in test environments
  • Memory leaks in event handling

Technical Improvements

  • Enhanced TypeScript type definitions
  • Better integration with @uplink-protocol/core ^0.0.11
  • Improved test environment compatibility
  • More robust service initialization and dependency injection

[0.1.6] - 2025-05-22

Fixed

  • General bug fixes and improvements

[0.1.5] - 2025-05-22

Fixed

  • General bug fixes and improvements

[0.1.4] - 2025-05-22

Fixed

  • General bug fixes and improvements

[0.1.3] - 2025-05-22

Fixed

  • General bug fixes and improvements

[0.1.2] - 2025-05-22

Fixed

  • General bug fixes and improvements

[0.1.1] - 2025-05-21

Fixed

  • Fixed issue in selectDate method where the date object was incorrectly created using mixed values from current date and parameters

[0.1.0] - 2025-05-20

Added

  • Initial release of the calendar controller
  • Core calendar API functionality
  • Calendar generation service
  • Date selection and validation services
  • Configuration service
  • Constraints service
  • Date formatting utilities
  • Navigation service
  • View state management
  • Event management system
  • TypeScript type definitions
  • Documentation with TypeDoc
  • Example implementations:
    • Calendar view
    • Date picker component
  • Internationalization
  • Month view functionality for easier month selection
  • Year view with configurable year ranges
  • Year range navigation methods (nextYearRange, prevYearRange, goToYearRange)
  • New interfaces: CalendarMonth, CalendarYear, YearRange
  • Methods to select specific months and years (selectMonth, selectYear)
  • Ability to customize year range size
  • Updated documentation for new view modes

Features

  • Framework-agnostic implementation
  • Configurable date constraints
  • Multiple date selection modes
  • Localization support
  • Customizable calendar grid generation
  • Date range selections
  • Event system for state changes
  • Internationalization