Skip to content

Commit 02492b1

Browse files
committed
fix(calendar): derive plain event weekday fields from the display location
Review follow-up: printCalendarEventWithTimezone formatted start-local/ end-local in the resolved display location but still computed start-day-of-week/end-day-of-week without it, so an instant that changes date in the override timezone could print a mismatched weekday. Use eventDaysOfWeekInLocation with the same resolved location (matching the JSON path) and add a CalendarEventCmd regression where the override crosses midnight (02:00Z Wednesday -> 22:00 Tuesday America/New_York).
1 parent fcaf707 commit 02492b1

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

internal/cmd/calendar_events_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,3 +744,49 @@ func TestCalendarEventsCmd_TimezoneFlag(t *testing.T) {
744744
t.Fatalf("expected override timezone in output, got: %q", out)
745745
}
746746
}
747+
748+
func TestCalendarEventCmd_TimezoneOverrideCrossDateWeekday(t *testing.T) {
749+
// 02:00Z on a Wednesday is 22:00 the previous day (Tuesday) in
750+
// America/New_York; the plain printer must derive the weekday fields from
751+
// the same display location as start-local/end-local.
752+
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
753+
switch {
754+
case r.URL.Path == "/users/me/calendarList" && r.Method == http.MethodGet:
755+
w.Header().Set("Content-Type", "application/json")
756+
_ = json.NewEncoder(w).Encode(map[string]any{
757+
"items": []map[string]any{
758+
{"id": "cal1", "summary": "Primary", "accessRole": "owner"},
759+
},
760+
})
761+
return
762+
case strings.Contains(r.URL.Path, "/calendars/cal1/events/e1") && r.Method == http.MethodGet:
763+
w.Header().Set("Content-Type", "application/json")
764+
_ = json.NewEncoder(w).Encode(map[string]any{
765+
"id": "e1",
766+
"summary": "Late call",
767+
"start": map[string]any{"dateTime": "2026-07-08T02:00:00Z"},
768+
"end": map[string]any{"dateTime": "2026-07-08T03:00:00Z"},
769+
})
770+
return
771+
default:
772+
http.NotFound(w, r)
773+
return
774+
}
775+
})
776+
svc, closeServer := newCalendarServiceForTest(t, handler)
777+
defer closeServer()
778+
779+
var output bytes.Buffer
780+
ctx := withCalendarTestService(newCmdRuntimeOutputContext(t, &output, io.Discard), svc)
781+
args := []string{"cal1", "e1", "--timezone", "America/New_York"}
782+
if err := runKong(t, &CalendarEventCmd{}, args, ctx, &RootFlags{Account: "[email protected]"}); err != nil {
783+
t.Fatalf("calendar event: %v", err)
784+
}
785+
out := output.String()
786+
if !strings.Contains(out, "start-local\t2026-07-07T22:00:00-04:00") {
787+
t.Fatalf("expected override-local start, got: %q", out)
788+
}
789+
if !strings.Contains(out, "start-day-of-week\tTuesday") || !strings.Contains(out, "end-day-of-week\tTuesday") {
790+
t.Fatalf("expected weekday fields in the override timezone, got: %q", out)
791+
}
792+
}

internal/cmd/calendar_print.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func printCalendarEventWithTimezone(u *ui.UI, event *calendar.Event, calendarTim
3535
}
3636

3737
u.Out().Linef("start\t%s", eventStart(event))
38-
startDay, endDay := eventDaysOfWeek(event)
38+
startDay, endDay := eventDaysOfWeekInLocation(event, loc)
3939
if startDay != "" {
4040
u.Out().Linef("start-day-of-week\t%s", startDay)
4141
}

0 commit comments

Comments
 (0)