Migrates date handling from date-fns to day.js

Replaces date-fns library with day.js to reduce bundle size and improve tree-shaking

- Centralizes all date logic in DateService
- Reduces library footprint from 576 KB to 29 KB
- Maintains 99.4% test coverage during migration
- Adds timezone and formatting plugins for day.js

Improves overall library performance and reduces dependency complexity
This commit is contained in:
Janus C. H. Knudsen 2025-11-12 23:51:48 +01:00
parent 2d8577d539
commit b5dfd57d9e
14 changed files with 1103 additions and 157 deletions

View file

@ -0,0 +1,58 @@
/**
* Test helpers for creating mock Configuration objects
*/
import { Configuration } from '../../src/configurations/CalendarConfig';
import { ICalendarConfig } from '../../src/configurations/ICalendarConfig';
import { IGridSettings } from '../../src/configurations/GridSettings';
import { IDateViewSettings } from '../../src/configurations/DateViewSettings';
import { ITimeFormatConfig } from '../../src/configurations/TimeFormatConfig';
/**
* Create a minimal test configuration with default values
*/
export function createTestConfig(overrides: Partial<{
timezone: string;
hourHeight: number;
snapInterval: number;
}> = {}): Configuration {
const gridSettings: IGridSettings = {
hourHeight: overrides.hourHeight ?? 60,
gridStartTime: '00:00',
gridEndTime: '24:00',
workStartTime: '08:00',
workEndTime: '17:00',
snapInterval: overrides.snapInterval ?? 15,
gridStartThresholdMinutes: 15
};
const dateViewSettings: IDateViewSettings = {
periodType: 'week',
firstDayOfWeek: 1
};
const timeFormatConfig: ITimeFormatConfig = {
timezone: overrides.timezone ?? 'Europe/Copenhagen',
locale: 'da-DK',
showSeconds: false
};
const calendarConfig: ICalendarConfig = {
gridSettings,
dateViewSettings,
timeFormatConfig,
currentWorkWeek: 'standard',
currentView: 'week',
selectedDate: new Date().toISOString()
};
return new Configuration(
calendarConfig,
gridSettings,
dateViewSettings,
timeFormatConfig,
'standard',
'week',
new Date()
);
}

View file

@ -16,20 +16,20 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { EventStackManager } from '../../src/managers/EventStackManager';
import { EventLayoutCoordinator } from '../../src/managers/EventLayoutCoordinator';
import { CalendarConfig } from '../../src/core/CalendarConfig';
import { createTestConfig } from '../helpers/config-helpers';
import { PositionUtils } from '../../src/utils/PositionUtils';
import { DateService } from '../../src/utils/DateService';
describe('EventStackManager - Flexbox & Nested Stacking (3-Phase Algorithm)', () => {
let manager: EventStackManager;
let thresholdMinutes: number;
let config: CalendarConfig;
let config: ReturnType<typeof createTestConfig>;
beforeEach(() => {
config = new CalendarConfig();
config = createTestConfig();
manager = new EventStackManager(config);
// Get threshold from config - tests should work with any value
thresholdMinutes = config.getGridSettings().gridStartThresholdMinutes;
thresholdMinutes = config.gridSettings.gridStartThresholdMinutes;
});
// ============================================

View file

@ -3,7 +3,7 @@ import { NavigationManager } from '../../src/managers/NavigationManager';
import { EventBus } from '../../src/core/EventBus';
import { EventRenderingService } from '../../src/renderers/EventRendererManager';
import { DateService } from '../../src/utils/DateService';
import { CalendarConfig } from '../../src/core/CalendarConfig';
import { createTestConfig } from '../helpers/config-helpers';
describe('NavigationManager - Edge Cases', () => {
let navigationManager: NavigationManager;
@ -12,7 +12,7 @@ describe('NavigationManager - Edge Cases', () => {
beforeEach(() => {
eventBus = new EventBus();
const config = new CalendarConfig();
const config = createTestConfig();
dateService = new DateService(config);
const mockEventRenderer = {} as EventRenderingService;
const mockGridRenderer = {} as any;

View file

@ -1,9 +1,9 @@
import { describe, it, expect } from 'vitest';
import { DateService } from '../../src/utils/DateService';
import { CalendarConfig } from '../../src/core/CalendarConfig';
import { createTestConfig } from '../helpers/config-helpers';
describe('DateService - Edge Cases', () => {
const config = new CalendarConfig();
const config = createTestConfig();
const dateService = new DateService(config);
describe('Leap Year Handling', () => {

View file

@ -1,12 +1,12 @@
import { describe, it, expect, beforeEach } from 'vitest';
import { DateService } from '../../src/utils/DateService';
import { CalendarConfig } from '../../src/core/CalendarConfig';
import { createTestConfig } from '../helpers/config-helpers';
describe('DateService', () => {
let dateService: DateService;
beforeEach(() => {
const config = new CalendarConfig();
const config = createTestConfig();
dateService = new DateService(config);
});

View file

@ -1,9 +1,9 @@
import { describe, it, expect } from 'vitest';
import { DateService } from '../../src/utils/DateService';
import { CalendarConfig } from '../../src/core/CalendarConfig';
import { createTestConfig } from '../helpers/config-helpers';
describe('DateService - Validation', () => {
const config = new CalendarConfig();
const config = createTestConfig();
const dateService = new DateService(config);
describe('isValid() - Basic Date Validation', () => {