Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 2.67 KB

File metadata and controls

59 lines (41 loc) · 2.67 KB

Calendar Widget First Day of Week Implementation Summary

Overview

This document summarizes the implementation of configurable first day of the week for the calendar widget. Users can now configure the calendar to start the week on any day (Sunday, Monday, Tuesday, etc.) and the calendar will properly display weekday headers and align the days accordingly.

Changes Made

1. Calendar Widget (calendar-widget.ts)

New Constants:

  • CALENDAR_WIDGET_WEEKDAY_ABBREVIATIONS: Maps weekday names to their abbreviations (Su, Mo, Tu, etc.)

New Function:

  • generateWeekdayHeaders(firstDayOfWeek: string): Generates HTML for weekday headers based on the selected first day of the week

Modified Logic:

  • Updated the calendar modal template to dynamically generate weekday headers using the new function
  • Fixed the showCalendarModal call to use the correct first day of week index

2. Calendar Widget Utilities (calendar-widget.utils.ts)

Improved Logic:

  • Fixed the renderCalendarDays function to properly calculate the starting day offset based on the first day of week setting
  • The calculation now correctly handles cases where the first day of the week is different from Sunday

How It Works

Weekday Headers Generation:

  1. The system determines the first day of the week from widget options
  2. It creates an ordered array of weekdays starting from the selected first day
  3. It generates HTML div elements for each weekday abbreviation
  4. Weekend days (Saturday and Sunday) are styled with red text

Calendar Grid Alignment:

  1. The system calculates the offset for the first day of the month based on the selected first day of the week
  2. It adds empty cells to properly align the calendar grid
  3. The days are then filled in sequence

Test Results

The implementation was tested with three configurations:

  1. Sunday as first day: Su Mo Tu We Th Fr Sa
  2. Monday as first day: Mo Tu We Th Fr Sa Su
  3. Saturday as first day: Sa Su Mo Tu We Th Fr

All configurations correctly display the weekday headers and align the calendar grid properly.

Benefits

  1. User Configurability: Users can choose their preferred starting day of the week
  2. Proper Visualization: Weekend days are highlighted in red regardless of the starting day
  3. Correct Alignment: Calendar grid correctly aligns with the selected starting day
  4. Internationalization Ready: The implementation can easily support different weekday preferences from various cultures

Future Improvements

  1. Add localization support for weekday abbreviations
  2. Implement additional styling options for different weekend days in various cultures
  3. Add validation for the first day of week setting