63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { type ClassValue, clsx } from 'clsx';
|
|
import { twMerge } from 'tailwind-merge';
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs));
|
|
}
|
|
|
|
export function generateId(): string {
|
|
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
}
|
|
|
|
export function formatTime(time: string): string {
|
|
const [hours, minutes] = time.split(':');
|
|
const hour = parseInt(hours);
|
|
const ampm = hour >= 12 ? 'PM' : 'AM';
|
|
const displayHour = hour % 12 || 12;
|
|
return `${displayHour}:${minutes} ${ampm}`;
|
|
}
|
|
|
|
export function formatDate(date: string): string {
|
|
return new Date(date).toLocaleDateString('en-US', {
|
|
weekday: 'long',
|
|
year: 'numeric',
|
|
month: 'long',
|
|
day: 'numeric',
|
|
});
|
|
}
|
|
|
|
export function isWithinBookingWindow(date: string): boolean {
|
|
const bookingDate = new Date(date);
|
|
const today = new Date();
|
|
const maxDate = new Date();
|
|
maxDate.setDate(today.getDate() + 6); // 7 days including today
|
|
|
|
// Reset time to start of day for comparison
|
|
today.setHours(0, 0, 0, 0);
|
|
maxDate.setHours(23, 59, 59, 999);
|
|
bookingDate.setHours(0, 0, 0, 0);
|
|
|
|
return bookingDate >= today && bookingDate <= maxDate;
|
|
}
|
|
|
|
export function getWeekDays(): Array<{ value: number; label: string }> {
|
|
return [
|
|
{ value: 0, label: 'Sunday' },
|
|
{ value: 1, label: 'Monday' },
|
|
{ value: 2, label: 'Tuesday' },
|
|
{ value: 3, label: 'Wednesday' },
|
|
{ value: 4, label: 'Thursday' },
|
|
{ value: 5, label: 'Friday' },
|
|
{ value: 6, label: 'Saturday' },
|
|
];
|
|
}
|
|
|
|
export function generateTimeSlots(startHour: number, endHour: number): string[] {
|
|
const slots = [];
|
|
for (let hour = startHour; hour < endHour; hour++) {
|
|
const hourStr = hour < 10 ? '0' + hour : hour.toString();
|
|
slots.push(`${hourStr}:00`);
|
|
}
|
|
return slots;
|
|
}
|