feat: add per-space timezone settings and improve booking management
- Add timezone configuration per space with fallback to system default - Implement timezone-aware datetime display and editing across frontend - Add migration for per_space_settings table - Update booking service to handle timezone conversions properly - Improve .gitignore to exclude build artifacts - Add comprehensive testing documentation Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,22 @@
|
||||
* Utility functions for timezone-aware datetime formatting.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ensure datetime string has UTC marker (Z suffix).
|
||||
* Backend returns naive datetimes without Z, which JS interprets as local time.
|
||||
* This function adds Z to treat them as UTC.
|
||||
*/
|
||||
export const ensureUTC = (datetime: string): string => {
|
||||
if (!datetime) return datetime
|
||||
if (datetime.endsWith('Z')) return datetime
|
||||
const tIndex = datetime.indexOf('T')
|
||||
if (tIndex !== -1) {
|
||||
const timePart = datetime.substring(tIndex + 1)
|
||||
if (timePart.includes('+') || timePart.lastIndexOf('-') > 0) return datetime
|
||||
}
|
||||
return datetime + 'Z'
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a datetime string in the user's timezone.
|
||||
*
|
||||
@@ -15,7 +31,7 @@ export const formatDateTime = (
|
||||
timezone: string = 'UTC',
|
||||
options?: Intl.DateTimeFormatOptions
|
||||
): string => {
|
||||
const date = new Date(datetime)
|
||||
const date = new Date(ensureUTC(datetime))
|
||||
|
||||
const defaultOptions: Intl.DateTimeFormatOptions = {
|
||||
timeZone: timezone,
|
||||
@@ -47,7 +63,7 @@ export const formatDate = (datetime: string, timezone: string = 'UTC'): string =
|
||||
* Format time only in user's timezone.
|
||||
*/
|
||||
export const formatTime = (datetime: string, timezone: string = 'UTC'): string => {
|
||||
const date = new Date(datetime)
|
||||
const date = new Date(ensureUTC(datetime))
|
||||
return new Intl.DateTimeFormat('ro-RO', {
|
||||
timeZone: timezone,
|
||||
hour: '2-digit',
|
||||
@@ -59,7 +75,7 @@ export const formatTime = (datetime: string, timezone: string = 'UTC'): string =
|
||||
* Format datetime with timezone abbreviation.
|
||||
*/
|
||||
export const formatDateTimeWithTZ = (datetime: string, timezone: string = 'UTC'): string => {
|
||||
const date = new Date(datetime)
|
||||
const date = new Date(ensureUTC(datetime))
|
||||
|
||||
const formatted = new Intl.DateTimeFormat('ro-RO', {
|
||||
timeZone: timezone,
|
||||
@@ -103,7 +119,7 @@ export const localDateTimeToISO = (localDateTime: string): string => {
|
||||
* Convert ISO datetime to datetime-local format for input field.
|
||||
*/
|
||||
export const isoToLocalDateTime = (isoDateTime: string, timezone: string = 'UTC'): string => {
|
||||
const date = new Date(isoDateTime)
|
||||
const date = new Date(ensureUTC(isoDateTime))
|
||||
|
||||
// Get the date components in the user's timezone
|
||||
const year = date.toLocaleString('en-US', { timeZone: timezone, year: 'numeric' })
|
||||
|
||||
Reference in New Issue
Block a user