Repository navigation
Conversation
Updating only the location of a whole-day event moved it: DTSTART came back a day early while DTEND stayed where it was. Two mismatches combine when the caller passes no dates and the stored ones are carried over. A VALUE=DATE arrives as local midnight, but the date that gets stored is derived with toISOString(), which is a day earlier in any zone east of UTC. On top of that the reader reports DTEND exclusively while the writer takes it inclusively and adds the day back itself, so the end survives by accident while the start does not. Reshape the carried values into the form the writer expects, so an untouched date stays untouched. Dates the caller supplies explicitly are left alone; that path is what langmail#91 addresses.
6668715 to
a01b1bc
Compare
dominik1001
left a comment
There was a problem hiding this comment.
Thank you for tracking this down. The carry-over fix works end to end: against Radicale, a whole-day event now keeps its stored DTSTART/DTEND when only its location is updated. However, three points need changes before this can be merged.
- Converting a timed event to whole-day regressed. Calling
update-eventwithwholeDay: trueand no dates now produces an event withDTENDequal toDTSTART. #116 added a unit test and a smoke check for this case, and both fail on this branch, which is why CI is red. Details are in the inline comment. - Explicit whole-day dates still use the old conversion. A given
startorendis still read withnew Date(x)and stored withtoISOString(), while the carried-over dates are now anchored at UTC. East of UTC, an explicit end therefore lands a day short, and a single update can mix both conventions. See the inline comment. recurrenceRule.untilstill moves. It is a stored whole-day date as well, so anUNTIL=20301230written by another client is re-written a day earlier east of UTC. The one-day shift can be handled here in the same way asstart/end. The full fix needs ts-caldav, however: it writesUNTILin extended format (2030-12-30) and cannot read its own output back (KlautNet/ts-caldav#29). For that reason this point is optional for this PR.
Failing tests for points 2 and 3 are on the branch test/whole-day-drift. It merges cleanly into this branch, and npm test plus npm run smoke then show what is left. Note that vitest and the CI smoke step now run in Europe/Berlin (#116), because these bugs only appear east of UTC.
| throw new Error(`Event not found: ${uid}`); | ||
| } | ||
|
|
||
| const staysWholeDay = wholeDay ?? existing.wholeDay; |
There was a problem hiding this comment.
staysWholeDay is also true when a timed event is being converted, i.e. wholeDay: true on an event whose existing.wholeDay is false. The carry then treats the timed end as an exclusive date and subtracts a day. For example, 10:00–11:00 on 2026-08-18 becomes DTSTART;VALUE=DATE:20260818 and DTEND;VALUE=DATE:20260818, while before this change the same call gave a one-day event. Gating the carry on existing.wholeDay should be sufficient.
| ...(staysWholeDay && carryWholeDayDates(existing, start, end)), | ||
| ...(summary !== undefined && { summary }), | ||
| ...(start !== undefined && { start: new Date(start) }), | ||
| ...(end !== undefined && { end: new Date(end) }), |
There was a problem hiding this comment.
These two lines still convert an explicit date with new Date(x), which the writer then formats with toISOString(). For a caller in Berlin, end: "2026-08-25T00:00:00+02:00" becomes 2026-08-24T22:00Z, so the event ends on the 24th instead of the 25th. Combined with a carried-over start, one update now uses two different conventions. The calendar day named in the string is what the caller means; the test reads an explicit whole-day end as the day it names on test/whole-day-drift covers this. (create-event has the same problem, but that can be a follow-up.)
ts-caldav writes a whole-day VALUE=DATE as the UTC day of the Date it is given and takes `end` as inclusive, while ical.js reads a VALUE=DATE back as local midnight with DTEND exclusive. East of UTC that shifts dates a day earlier in two places: - An explicit start/end/until such as 2026-09-30T00:00:00+09:00 was stored as 2026-09-29 (create-event and update-event). - An update that changes only another field (e.g. location) carried the stored dates back as is, moving DTSTART a day earlier. Add src/tools/whole-day-date.ts with toWholeDayDate() for ISO input and storedStartToWholeDayDate()/storedEndToWholeDayDate() for carried-over dates, and use them in create-event and update-event. Timed events are unchanged, as is converting a timed event to whole-day without dates. Supersedes #91 and #95. Co-authored-by: Jan Baer <jan@janbaer.de> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CjZppzN6ZPGrd6Bvxxe4Uh
|
Thanks a lot for this, @janbaer! Your carry-over fix is now part of #125, which just merged. That PR combined it with #91's fix for explicitly passed dates. Your Closing this one as superseded by #125. Generated by Claude Code |
Updating only the location of a whole-day event moves it: DTSTART comes back a day early while DTEND stays where it was.
Two mismatches combine when the caller passes no dates and the stored ones are carried over from the existing event:
VALUE=DATEarrives as local midnight, but the date that gets stored is derived withtoISOString(), which is a day earlier in any zone east of UTC.So the end survives by accident while the start does not. This reshapes the carried values into the form the writer expects, which makes an untouched date stay untouched.
It also closes a second, pre-existing bug that the title does not cover. West of UTC the
toISOString()truncation loses nothing, soendwas carried through with no inclusive/exclusive correction at all and every update pushed DTEND one day later — a drift that compounds on repeated edits.Dates the caller supplies explicitly are deliberately left alone: that path is what #91 addresses, and I did not want the two to overlap.
Verified against mailbox.org (Open-Xchange): a whole-day event created for 10 to 12 March keeps both boundaries to the millisecond when only its location is changed. Three tests added; reverting the fix while keeping them fails under both
TZ=UTCandTZ=Europe/Berlin.One caveat worth knowing: CI runs under
TZ=UTC, wherenew Date(2026, 7, 18)andDate.UTC(2026, 7, 18)are the same instant, so the DTSTART half of the bug cannot be reproduced there. The regression test fails on CI only through the DTEND half. Pinning a non-UTCTZfor the test run would close that gap, but that is your call, not something I wanted to change unasked.