Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
d985d6d
1
Parent(s): b38cc4d
feat: use client device timezone for date/time display
Browse files
frontend/app/appointments/page.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import { useAuth } from '@/contexts/AuthContext'
|
|
| 12 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 13 |
import { CreateAppointmentModal } from '@/components/bookings/CreateAppointmentModal'
|
| 14 |
import { cn } from '@/lib/utils'
|
|
|
|
| 15 |
|
| 16 |
type ViewMode = 'day' | 'week' | 'month'
|
| 17 |
|
|
@@ -279,9 +280,13 @@ export default function AppointmentsPage() {
|
|
| 279 |
</div>
|
| 280 |
<div>
|
| 281 |
<h1 className="text-xl md:text-3xl font-bold text-white tracking-tight">Календарь записей</h1>
|
| 282 |
-
<div className="flex items-center gap-
|
| 283 |
-
<
|
| 284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
</div>
|
| 286 |
</div>
|
| 287 |
</div>
|
|
|
|
| 12 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 13 |
import { CreateAppointmentModal } from '@/components/bookings/CreateAppointmentModal'
|
| 14 |
import { cn } from '@/lib/utils'
|
| 15 |
+
import { getClientTimezone, getTimezoneDisplayName } from '@/lib/timezone'
|
| 16 |
|
| 17 |
type ViewMode = 'day' | 'week' | 'month'
|
| 18 |
|
|
|
|
| 280 |
</div>
|
| 281 |
<div>
|
| 282 |
<h1 className="text-xl md:text-3xl font-bold text-white tracking-tight">Календарь записей</h1>
|
| 283 |
+
<div className="flex items-center gap-3 text-xs md:text-sm text-slate-400 mt-0.5 md:mt-1">
|
| 284 |
+
<div className="flex items-center gap-1.5">
|
| 285 |
+
<span className="w-1.5 h-1.5 md:w-2 md:h-2 rounded-full bg-emerald-500"></span>
|
| 286 |
+
<span>Онлайн запись</span>
|
| 287 |
+
</div>
|
| 288 |
+
<span className="text-slate-600">•</span>
|
| 289 |
+
<span className="text-slate-500">{getTimezoneDisplayName()}</span>
|
| 290 |
</div>
|
| 291 |
</div>
|
| 292 |
</div>
|
frontend/components/bookings/BookingModal.tsx
CHANGED
|
@@ -7,6 +7,7 @@ import { ru } from 'date-fns/locale'
|
|
| 7 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 8 |
import { bookingsApi } from '@/lib/api'
|
| 9 |
import { cn } from '@/lib/utils'
|
|
|
|
| 10 |
|
| 11 |
interface BookingModalProps {
|
| 12 |
isOpen: boolean
|
|
|
|
| 7 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 8 |
import { bookingsApi } from '@/lib/api'
|
| 9 |
import { cn } from '@/lib/utils'
|
| 10 |
+
import { getClientTimezone, getTimezoneDisplayName } from '@/lib/timezone'
|
| 11 |
|
| 12 |
interface BookingModalProps {
|
| 13 |
isOpen: boolean
|
frontend/lib/timezone.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Timezone utilities - uses client device timezone
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
/**
|
| 6 |
+
* Get the browser/device timezone
|
| 7 |
+
* Returns IANA timezone string like 'Asia/Bishkek' or 'Europe/Moscow'
|
| 8 |
+
*/
|
| 9 |
+
export function getClientTimezone(): string {
|
| 10 |
+
try {
|
| 11 |
+
return Intl.DateTimeFormat().resolvedOptions().timeZone
|
| 12 |
+
} catch {
|
| 13 |
+
return 'UTC'
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
/**
|
| 18 |
+
* Get timezone offset in hours from UTC
|
| 19 |
+
* Positive for east of UTC (e.g., +6 for Asia/Bishkek)
|
| 20 |
+
*/
|
| 21 |
+
export function getTimezoneOffset(): number {
|
| 22 |
+
return -new Date().getTimezoneOffset() / 60
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
/**
|
| 26 |
+
* Format date in client's local timezone
|
| 27 |
+
*/
|
| 28 |
+
export function formatLocalDate(date: Date | string, formatStr: string = 'dd.MM.yyyy'): string {
|
| 29 |
+
const d = typeof date === 'string' ? new Date(date) : date
|
| 30 |
+
|
| 31 |
+
const options: Intl.DateTimeFormatOptions = {}
|
| 32 |
+
|
| 33 |
+
if (formatStr.includes('dd') || formatStr.includes('d')) {
|
| 34 |
+
options.day = formatStr.includes('dd') ? '2-digit' : 'numeric'
|
| 35 |
+
}
|
| 36 |
+
if (formatStr.includes('MM') || formatStr.includes('M')) {
|
| 37 |
+
options.month = formatStr.includes('MMMM') ? 'long' : formatStr.includes('MMM') ? 'short' : '2-digit'
|
| 38 |
+
}
|
| 39 |
+
if (formatStr.includes('yyyy') || formatStr.includes('y')) {
|
| 40 |
+
options.year = 'numeric'
|
| 41 |
+
}
|
| 42 |
+
if (formatStr.includes('HH') || formatStr.includes('H')) {
|
| 43 |
+
options.hour = '2-digit'
|
| 44 |
+
options.hour12 = false
|
| 45 |
+
}
|
| 46 |
+
if (formatStr.includes('mm') || formatStr.includes('m')) {
|
| 47 |
+
options.minute = '2-digit'
|
| 48 |
+
}
|
| 49 |
+
if (formatStr.includes('EEEE') || formatStr.includes('EEE')) {
|
| 50 |
+
options.weekday = formatStr.includes('EEEE') ? 'long' : 'short'
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
return d.toLocaleString('ru-RU', options)
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
/**
|
| 57 |
+
* Format time in client's local timezone
|
| 58 |
+
*/
|
| 59 |
+
export function formatLocalTime(date: Date | string): string {
|
| 60 |
+
const d = typeof date === 'string' ? new Date(date) : date
|
| 61 |
+
return d.toLocaleTimeString('ru-RU', { hour: '2-digit', minute: '2-digit', hour12: false })
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
/**
|
| 65 |
+
* Format full datetime in client's local timezone
|
| 66 |
+
*/
|
| 67 |
+
export function formatLocalDateTime(date: Date | string): string {
|
| 68 |
+
const d = typeof date === 'string' ? new Date(date) : date
|
| 69 |
+
return d.toLocaleString('ru-RU', {
|
| 70 |
+
day: '2-digit',
|
| 71 |
+
month: 'long',
|
| 72 |
+
year: 'numeric',
|
| 73 |
+
hour: '2-digit',
|
| 74 |
+
minute: '2-digit',
|
| 75 |
+
hour12: false
|
| 76 |
+
})
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
/**
|
| 80 |
+
* Convert local date/time to ISO string for API
|
| 81 |
+
* This preserves the local time when sent to server
|
| 82 |
+
*/
|
| 83 |
+
export function localToISOString(date: Date): string {
|
| 84 |
+
return date.toISOString()
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
/**
|
| 88 |
+
* Parse ISO string from API to local Date
|
| 89 |
+
*/
|
| 90 |
+
export function isoToLocalDate(isoString: string): Date {
|
| 91 |
+
return new Date(isoString)
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* Get current date/time in client timezone
|
| 96 |
+
*/
|
| 97 |
+
export function nowLocal(): Date {
|
| 98 |
+
return new Date()
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
/**
|
| 102 |
+
* Check if date is today in client timezone
|
| 103 |
+
*/
|
| 104 |
+
export function isToday(date: Date | string): boolean {
|
| 105 |
+
const d = typeof date === 'string' ? new Date(date) : date
|
| 106 |
+
const today = new Date()
|
| 107 |
+
return d.toDateString() === today.toDateString()
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
/**
|
| 111 |
+
* Get timezone display name
|
| 112 |
+
*/
|
| 113 |
+
export function getTimezoneDisplayName(): string {
|
| 114 |
+
const tz = getClientTimezone()
|
| 115 |
+
const offset = getTimezoneOffset()
|
| 116 |
+
const sign = offset >= 0 ? '+' : ''
|
| 117 |
+
return `${tz} (UTC${sign}${offset})`
|
| 118 |
+
}
|