Adds resource scheduling and unavailability tracking
Introduces comprehensive schedule management for resources: - Adds DateService with advanced time and date utilities - Implements ResourceScheduleService for managing work hours - Creates ScheduleRenderer to visualize unavailable time zones - Extends resource model to support default weekly schedules Enables granular tracking of resource availability and working hours
This commit is contained in:
parent
400de8c9d5
commit
a2b95515fd
17 changed files with 563 additions and 36 deletions
|
|
@ -1,8 +1,20 @@
|
|||
import dayjs from 'dayjs';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import timezone from 'dayjs/plugin/timezone';
|
||||
import isoWeek from 'dayjs/plugin/isoWeek';
|
||||
import { ITimeFormatConfig } from './ITimeFormatConfig';
|
||||
|
||||
// Enable dayjs plugins
|
||||
dayjs.extend(utc);
|
||||
dayjs.extend(timezone);
|
||||
dayjs.extend(isoWeek);
|
||||
|
||||
export class DateService {
|
||||
constructor(private config: ITimeFormatConfig) {}
|
||||
private timezone: string;
|
||||
|
||||
constructor(private config: ITimeFormatConfig) {
|
||||
this.timezone = config.timezone;
|
||||
}
|
||||
|
||||
parseISO(isoString: string): Date {
|
||||
return dayjs(isoString).toDate();
|
||||
|
|
@ -18,4 +30,74 @@ export class DateService {
|
|||
monday.add(i, 'day').format('YYYY-MM-DD')
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// FORMATTING
|
||||
// ============================================
|
||||
|
||||
formatTime(date: Date, showSeconds = false): string {
|
||||
const pattern = showSeconds ? 'HH:mm:ss' : 'HH:mm';
|
||||
return dayjs(date).format(pattern);
|
||||
}
|
||||
|
||||
formatTimeRange(start: Date, end: Date): string {
|
||||
return `${this.formatTime(start)} - ${this.formatTime(end)}`;
|
||||
}
|
||||
|
||||
formatDate(date: Date): string {
|
||||
return dayjs(date).format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
getDateKey(date: Date): string {
|
||||
return this.formatDate(date);
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// TIME CALCULATIONS
|
||||
// ============================================
|
||||
|
||||
timeToMinutes(timeString: string): number {
|
||||
const parts = timeString.split(':').map(Number);
|
||||
const hours = parts[0] || 0;
|
||||
const minutes = parts[1] || 0;
|
||||
return hours * 60 + minutes;
|
||||
}
|
||||
|
||||
minutesToTime(totalMinutes: number): string {
|
||||
const hours = Math.floor(totalMinutes / 60);
|
||||
const minutes = totalMinutes % 60;
|
||||
return dayjs().hour(hours).minute(minutes).format('HH:mm');
|
||||
}
|
||||
|
||||
getMinutesSinceMidnight(date: Date): number {
|
||||
const d = dayjs(date);
|
||||
return d.hour() * 60 + d.minute();
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// UTC CONVERSIONS
|
||||
// ============================================
|
||||
|
||||
toUTC(localDate: Date): string {
|
||||
return dayjs.tz(localDate, this.timezone).utc().toISOString();
|
||||
}
|
||||
|
||||
fromUTC(utcString: string): Date {
|
||||
return dayjs.utc(utcString).tz(this.timezone).toDate();
|
||||
}
|
||||
|
||||
// ============================================
|
||||
// DATE CREATION
|
||||
// ============================================
|
||||
|
||||
createDateAtTime(baseDate: Date | string, timeString: string): Date {
|
||||
const totalMinutes = this.timeToMinutes(timeString);
|
||||
const hours = Math.floor(totalMinutes / 60);
|
||||
const minutes = totalMinutes % 60;
|
||||
return dayjs(baseDate).startOf('day').hour(hours).minute(minutes).toDate();
|
||||
}
|
||||
|
||||
getISOWeekDay(date: Date | string): number {
|
||||
return dayjs(date).isoWeekday(); // 1=Monday, 7=Sunday
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue