Project IT Calendar 1.0.0
Advanced Calendar Applet for Cinnamon Desktop Environment
Loading...
Searching...
No Matches
CalendarDay.ts
Go to the documentation of this file.
1/**
2 * Project IT Calendar - Day Interface & Type Definitions
3 * =======================================================
4 *
5 * This file contains TypeScript type definitions and interfaces
6 * used throughout the calendar application for type-safe date handling.
7 *
8 * IMPORTANT ARCHITECTURAL NOTE:
9 * -----------------------------
10 * This file contains ONLY type definitions - it produces NO JavaScript
11 * output when compiled. These types exist purely for TypeScript's
12 * static type checking and development-time tooling.
13 *
14 * Why separate type definitions?
15 * 1. Centralized type management: All date-related types in one place
16 * 2. Reusability: Multiple components can import the same types
17 * 3. Consistency: Ensures all components use the same type definitions
18 * 4. Documentation: Serves as living documentation of the data model
19 *
20 * ------------------------------------------------------------------
21 * TYPE SYSTEM IN CINNAMON/GJS CONTEXT:
22 * ------------------------------------------------------------------
23 * TypeScript types are STRIPPED at compile time when using:
24 * - Module: "None" in tsconfig.json
25 * - OutFile: Single-file bundling for Cinnamon applets
26 *
27 * This means:
28 * - These interfaces EXIST only during development
29 * - They provide IDE autocompletion and error checking
30 * - They are REMOVED in production (no runtime overhead)
31 * - No global export needed (types don't exist at runtime)
32 *
33 * ------------------------------------------------------------------
34 * USAGE BY OTHER COMPONENTS:
35 * ------------------------------------------------------------------
36 * 1. CalendarLogic.ts (Primary Consumer):
37 * - Uses DayType enum to categorize days
38 * - Uses CalendarDay interface for structured date information
39 * - Provides type-safe holiday calculations
40 *
41 * 2. CalendarView.ts (Potential Consumer):
42 * - Could use these types for day cell rendering
43 * - Ensures consistency between logic and view layers
44 *
45 * 3. EventManager.ts (Potential Consumer):
46 * - Could use CalendarDay for event-date associations
47 *
48 * ------------------------------------------------------------------
49 * @author Arnold Schiller <calendar@projektit.de>
50 * @link https://github.com/ArnoldSchiller/calendar
51 * @link https://projektit.de/kalender
52 * @license GPL-3.0-or-later
53 */
54
55/* ================================================================
56 * DAY TYPE ENUMERATION
57 * ================================================================
58 *
59 * Defines all possible classifications for calendar days.
60 * Used for visual styling, behavior rules, and holiday logic.
61 *
62 * IMPORTANT: These values are used in:
63 * 1. CSS class selection (calendar-workday, calendar-holiday, etc.)
64 * 2. Business logic (is this a work day?)
65 * 3. UI rendering (different colors/styles per type)
66 */
67
68export type DayType =
69 /**
70 * Standard working day (Monday-Friday, not a holiday).
71 * Default styling, no special behavior.
72 */
73 'WORKDAY' |
74
75 /**
76 * Official statutory holiday.
77 * Banks/schools closed, legal holiday in the region.
78 * Styled with holiday colors, may have special behavior.
79 */
80 'PUBLIC_HOLIDAY' |
81
82 /**
83 * Unofficial observance or traditional holiday.
84 * Normal work day but culturally significant.
85 * May have subtle visual indication.
86 */
87 'OBSERVANCE' |
88
89 /**
90 * The current system date (today).
91 * Always highlighted regardless of day type.
92 * Special "today" styling applied.
93 */
94 'TODAY' |
95
96 /**
97 * Saturday or Sunday (in most regions).
98 * Weekend styling applied, may affect business logic.
99 */
100 'WEEKEND' |
101
102 /**
103 * Placeholder cell for calendar grid alignment.
104 * Days from previous/next month in current month view.
105 * Typically grayed out or visually distinct.
106 */
107 'EMPTY';
108
109/* ================================================================
110 * CALENDAR DAY INTERFACE
111 * ================================================================
112 *
113 * Complete structured representation of a single calendar day.
114 * Used when passing day information between components.
115 *
116 * DESIGN DECISION: Why not just use Date objects?
117 * - Dates alone don't carry classification information
118 * - Need to associate metadata (holiday names, day types)
119 * - Allows consistent data structure across the application
120 */
121
122export interface CalendarDay {
123 /**
124 * The day number as displayed in the calendar (1-31).
125 * String type allows for special cases like "31*" or formatting.
126 */
127 dayNumber: string;
128
129 /**
130 * Full JavaScript Date object for this day.
131 * Used for calculations, comparisons, and time-based operations.
132 */
133 date: Date;
134
135 /**
136 * Classification of this day (workday, holiday, weekend, etc.).
137 * Determines visual styling and business logic behavior.
138 */
139 type: DayType;
140
141 /**
142 * Human-readable description, typically holiday names.
143 * Examples: "New Year's Day", "Christmas", "German Unity Day"
144 * Empty string for normal days.
145 */
146 description: string;
147
148 /**
149 * Flag indicating if this is an official public holiday.
150 * true: Banks/schools closed, legal holiday
151 * false: Normal work day (even if it's an observance)
152 *
153 * Different from type='PUBLIC_HOLIDAY' because:
154 * - A day can be both TODAY and PUBLIC_HOLIDAY
155 * - This flag focuses on legal status, not classification
156 */
157 isPublic: boolean;
158}
159
160/* ================================================================
161 * TYPE GUARD FUNCTIONS (Potential Future Enhancement)
162 * ================================================================
163 *
164 * These functions don't exist yet but show how types could be used:
165 *
166 * function isWorkDay(day: CalendarDay): boolean {
167 * return day.type === 'WORKDAY';
168 * }
169 *
170 * function isHoliday(day: CalendarDay): boolean {
171 * return day.type === 'PUBLIC_HOLIDAY' || day.type === 'OBSERVANCE';
172 * }
173 *
174 * function isWeekend(day: CalendarDay): boolean {
175 * return day.type === 'WEEKEND';
176 * }
177 */
178
179/* ================================================================
180 * DEVELOPER NOTES
181 * ================================================================
182 *
183 * NO GLOBAL EXPORT NEEDED:
184 * ------------------------
185 * Unlike other files in this project, we DO NOT use:
186 * (global as any).CalendarDay = CalendarDay;
187 *
188 * Reason: These are TypeScript-only type definitions that are
189 * completely removed during compilation. They don't exist at
190 * runtime in the GJS/Cinnamon environment.
191 *
192 * COMPILATION BEHAVIOR:
193 * ---------------------
194 * With tsconfig.json setting: "module": "none"
195 * - TypeScript interfaces and type aliases produce NO JavaScript
196 * - They exist only for type checking during development
197 * - No runtime code is generated for this file
198 *
199 * This is intentional and correct for type definition files.
200 */
201
202/* ================================================================
203 * EXAMPLE USAGE IN OTHER FILES
204 * ================================================================
205 *
206 * // In CalendarLogic.ts:
207 * import { CalendarDay, DayType } from './CalendarDay';
208 *
209 * function createCalendarDay(date: Date, holidayName: string): CalendarDay {
210 * return {
211 * dayNumber: date.getDate().toString(),
212 * date: date,
213 * type: holidayName ? 'PUBLIC_HOLIDAY' : 'WORKDAY',
214 * description: holidayName,
215 * isPublic: !!holidayName
216 * };
217 * }
218 *
219 * // In CalendarView.ts (if using TypeScript strictly):
220 * function renderDayCell(day: CalendarDay) {
221 * // TypeScript knows day has dayNumber, type, description, etc.
222 * applyStyle(day.type); // Type-safe access
223 * setText(day.dayNumber);
224 * }
225 */
226
227/* ================================================================
228 * TODOs AND FUTURE ENHANCEMENTS
229 * ================================================================
230 *
231 * TODO: Add DayColor interface for theming support
232 * TODO: Add CalendarWeek type for week-based operations
233 * TODO: Add DateRange type for event span calculations
234 * TODO: Add type guard functions for runtime type checking
235 * TODO: Consider adding i18n keys to descriptions for translation
236 */