mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
fix(reminders): read a first-due date sent as a date as that day in the user's zone
A reminder's first-due date could only be sent as a date-time, and the web form sent the browser's local midnight, so a browser set to a zone other than the profile's could move the day. The API now also takes a bare calendar date and stores it as that day's midnight in the user's zone, and the web form sends the date itself. A date-time still means the instant it names.
This commit is contained in:
1 parent
b6b51fcb5e
commit
9311337997
8 files changed
+101
-20
No files matched your search
@@ -181,11 +181,13 @@ function toDateInputValue(iso: string | null): string {
|
||||
return new Date(d.getTime() - offset * 60 * 1000).toISOString().slice(0, 10);
|
||||
}
|
||||
|
||||
/** `<input type="date">` value → an ISO instant at local midnight, or null. */
|
||||
/**
|
||||
* `<input type="date">` value → the calendar date itself, or null. The server
|
||||
* reads a bare date as that day in the profile's zone, so a browser set to
|
||||
* another zone cannot move the first-due day.
|
||||
*/
|
||||
function fromDateInputValue(value: string): string | null {
|
||||
if (!value) return null;
|
||||
const d = new Date(`${value}T00:00:00`);
|
||||
return Number.isNaN(d.getTime()) ? null : d.toISOString();
|
||||
return /^\d{4}-\d{2}-\d{2}$/.test(value) ? value : null;
|
||||
}
|
||||
|
||||
interface FormState {
|
||||
|
||||
Reference in new issue
Block a user