| /** | |
| * Timezone utility functions for the frontend scheduling system. | |
| */ | |
| /** | |
| * Parse a timezone-prefixed schedule time string and extract the time part. | |
| * @param {string} scheduleTime - Schedule time in format "Day HH:MM::::timezone" or "Day HH:MM" | |
| * @returns {string} Time part without timezone | |
| */ | |
| export const parseScheduleTime = (scheduleTime) => { | |
| if (!scheduleTime) return scheduleTime; | |
| if (scheduleTime.includes('::::')) { | |
| return scheduleTime.split('::::')[0]; | |
| } | |
| // Legacy format without timezone | |
| return scheduleTime; | |
| }; | |
| /** | |
| * Get the user's timezone from the browser. | |
| * @returns {string} Timezone string (e.g., "America/New_York") | |
| */ | |
| export const getUserTimezone = () => { | |
| try { | |
| return Intl.DateTimeFormat().resolvedOptions().timeZone; | |
| } catch (error) { | |
| console.error('Error getting timezone:', error); | |
| return 'UTC'; // Fallback | |
| } | |
| }; | |
| /** | |
| * Format a schedule time for display (day and time only, no timezone). | |
| * @param {string} scheduleTime - Schedule time string | |
| * @returns {string} Formatted time for display | |
| */ | |
| export const formatScheduleForDisplay = (scheduleTime) => { | |
| const parsedTime = parseScheduleTime(scheduleTime); | |
| if (!parsedTime) return ''; | |
| // Split into day and time parts | |
| const parts = parsedTime.trim().split(' '); | |
| if (parts.length >= 2) { | |
| const day = parts[0]; | |
| const time = parts[1]; | |
| return `${day} ${time}`; | |
| } | |
| return parsedTime; | |
| }; | |
| /** | |
| * Check if a schedule time has timezone information. | |
| * @param {string} scheduleTime - Schedule time string | |
| * @returns {boolean} True if timezone is included | |
| */ | |
| export const hasTimezone = (scheduleTime) => { | |
| return scheduleTime && scheduleTime.includes('::::'); | |
| }; | |
| /** | |
| * Extract timezone from a schedule time string. | |
| * @param {string} scheduleTime - Schedule time string | |
| * @returns {string|null} Timezone string or null if not present | |
| */ | |
| export const extractTimezone = (scheduleTime) => { | |
| if (!scheduleTime || !scheduleTime.includes('::::')) { | |
| return null; | |
| } | |
| return scheduleTime.split('::::')[1]?.trim() || null; | |
| }; |