Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 14, 2025

Problem

When users entered seminar dates and times, the system was using their local browser timezone instead of Pisa time. This caused incorrect times to be stored in the database and displayed to users.

For example:

  • A user in New York (UTC-5) entering "14:00" for a seminar would have it stored as "19:00 UTC" in the database
  • When displayed to users in Pisa, this would show as "20:00" (in winter) or "21:00" (in summer with DST)
  • Different users would see different times depending on their timezone

This violated the requirement that all seminar times should be entered and displayed in Pisa time, regardless of the user's location.

Solution

Changed all date/time handling to use UTC methods throughout the application, treating all input and output as Pisa time. The key insight is to store times directly in UTC without any timezone conversion, and consistently use UTC methods for both reading and writing.

Changes Made

Frontend Input Component (src/components/DatetimeInput.js):

  • Changed updateDatetimeFromString() to use setUTCFullYear(), setUTCMonth(), setUTCDate(), setUTCHours(), setUTCMinutes() instead of their local timezone equivalents
  • Updated formatDate() to use getUTCFullYear(), getUTCMonth(), etc.
  • Modified DatetimeInput component to initialize state using UTC getters

Display Functions - Added timeZone: 'UTC' parameter to all date formatting:

  • widgets/src/utils.js - Widget display functions (formatDate, formatTime)
  • src/processes/RoomsBookings.js - Room booking time display
  • server/controllers/processes/seminars.js - Seminar notification formatting
  • server/controllers/processes/visits.js - Visit notification formatting
  • server/worker.js - Background worker notification formatting

Result

Now all datetime handling is timezone-independent:

  • ✅ Users enter times thinking in Pisa time (e.g., "14:00")
  • ✅ Times are stored in MongoDB as UTC without conversion (e.g., "2024-10-15T14:00:00.000Z")
  • ✅ All users see the same time regardless of their timezone (e.g., "14:00")
  • ✅ Consistent behavior across the entire application (forms, widgets, notifications)

Testing

Verified that:

  • Application builds successfully
  • Users in different timezones (New York UTC-5, Rome UTC+1/+2, Tokyo UTC+9) all see identical times
  • Input and display are consistent
  • The fix applies to all datetime inputs (seminars, lessons, room bookings, etc.)

Closes issue about "Ora locale nell'inserimento dei dati" (Local time in data entry).

Original prompt

This section details on the original issue you should resolve

<issue_title>Ora locale nell'inserimento dei dati</issue_title>
<issue_description>Nell'inserimento dei dati dei seminari viene presa l'ora locale (dell'utente) e viene convertita in ora di Pisa (server). Andrebbe sempre inserita l'ora di Pisa.

E.</issue_description>

<agent_instructions>controlla anche se è già stato risolto...</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #54


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@paolini paolini marked this pull request as ready for review October 14, 2025 07:50
Copilot AI changed the title [WIP] Fix timezone handling for seminar data input Fix timezone issue in seminar datetime input - always use Pisa time Oct 14, 2025
Copilot AI requested a review from paolini October 14, 2025 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants