Batch update, WIP

This commit is contained in:
Janus C. H. Knudsen 2025-11-03 22:04:37 +01:00
parent 8ec5f52872
commit 989c9bd69d
25 changed files with 68 additions and 123 deletions

View file

@ -9,32 +9,24 @@
*/
import { DateService } from './DateService';
export interface ITimeFormatSettings {
timezone: string;
use24HourFormat: boolean;
locale: string;
dateFormat: 'locale' | 'technical';
showSeconds: boolean;
}
import { ITimeFormatConfig } from '../configurations/TimeFormatConfig';
export class TimeFormatter {
private static settings: ITimeFormatSettings = {
timezone: 'Europe/Copenhagen', // Default to Denmark
use24HourFormat: true, // 24-hour format standard in Denmark
locale: 'da-DK', // Danish locale
dateFormat: 'technical', // Use technical format yyyy-mm-dd hh:mm:ss
showSeconds: false // Don't show seconds by default
};
private static settings: ITimeFormatConfig | null = null;
// DateService will be initialized lazily to avoid circular dependency with CalendarConfig
private static dateService: DateService | null = null;
private static getDateService(): DateService {
if (!TimeFormatter.dateService) {
if (!TimeFormatter.settings) {
throw new Error('TimeFormatter must be configured before use. Call TimeFormatter.configure() first.');
}
// Create a minimal config object for DateService
const config = {
getTimezone: () => TimeFormatter.settings.timezone
timeFormatConfig: {
timezone: TimeFormatter.settings.timezone
}
};
TimeFormatter.dateService = new DateService(config as any);
}
@ -43,9 +35,10 @@ export class TimeFormatter {
/**
* Configure time formatting settings
* Must be called before using TimeFormatter
*/
static configure(settings: Partial<ITimeFormatSettings>): void {
TimeFormatter.settings = { ...TimeFormatter.settings, ...settings };
static configure(settings: ITimeFormatConfig): void {
TimeFormatter.settings = settings;
// Reset DateService to pick up new timezone
TimeFormatter.dateService = null;
}
@ -71,6 +64,9 @@ export class TimeFormatter {
* @returns Formatted time string (e.g., "09:00")
*/
private static format24Hour(date: Date): string {
if (!TimeFormatter.settings) {
throw new Error('TimeFormatter must be configured before use. Call TimeFormatter.configure() first.');
}
const localDate = TimeFormatter.convertToLocalTime(date);
return TimeFormatter.getDateService().formatTime(localDate, TimeFormatter.settings.showSeconds);
}