Respect user date format for activities, calendar events and core date fields #683
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes OpenCATS consistently respect the user date format (
MM-DD-YYvsDD-MM-YY) across the main UI entry points for dates, while keeping the database storage unchanged (YYYY-MM-DD/YYYY-MM-DD HH:MM:SS).Concretely:
Activities (candidates & contacts)
window.CATSUserDateFormat(MM-DD-YYorDD-MM-YY) for:dateFormatFlagderived from$_SESSION['CATS']->isDateDMY(), before converting toYYYY-MM-DD HH:MM:SS.Calendar events
DateInputfields fordateAddanddateEdit.SetDateInputDate(...)inCalendarUI.js.dateAdd/dateEditusing the same user date format flag inCalendarUI.php, then convert toYYYY-MM-DDfor storage.Candidate availability (
dateAvailable)dateAvailableusing the user date format on add/edit.YYYY-MM-DDbefore saving.Job order start date (
startDate)startDateusing the user date format on add/edit.YYYY-MM-DDbefore saving.Extra fields of type “Date”
DD-MM-YYorMM-DD-YY, working both for logged-in users and the careers portal.DateInput(..., userDateFormat, ...).MM-DD-YYrepresentation for storage in the extra field value.Across all these changes:
YYYY-MM-DD/YYYY-MM-DD HH:MM:SS), and only the parsing/validation layer was updated.Motivation
Previously, OpenCATS assumed
MM-DD-YYin several places in the UI and server-side validation, regardless of the user’s configured date format. This led to a few concrete problems:Bug in activity editing (Day/Month mixed up when editing activities if UK locale set #344):
When the user date format was set to
DD-MM-YYYY, existing activity dates were still parsed asMM-DD-YY. As a result, day and month were swapped when editing (e.g.04-08-25intended as 4 August became 8 April when saved).Inconsistent UX when entering dates:
Some forms always rendered
DateInput(..., 'MM-DD-YY', ...)even when the rest of the UI (and the user’s expectation) usedDD-MM-YY. This made it easy to enter a “valid-looking” date that was later misinterpreted on the server.Risk of silently wrong dates in the database:
Because the database expects
YYYY-MM-DD, but the conversion step assumedMM-DD-YY, users withDD-MM-YYcould end up storing logically incorrect dates (day/month swapped) without any error.This PR addresses these issues by:
isDateDMY()/ site preference for unauthenticated users).DateInput/DateInputForDOM/SetDateInputDatecalls.YYYY-MM-DD/YYYY-MM-DD HH:MM:SSfor storage.The goal is to make date handling predictable and safe for both
MM-DD-YYandDD-MM-YYusers, without changing the existing database schema or storage format.