Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/cmd/calendar_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ func extractTimezone(value string) string {
return candidate
}
}

// Fallback for fixed whole-hour offsets when no regional timezone match is found.
// NOTE: IANA "Etc/GMT" names use reversed signs (e.g. +02:00 => Etc/GMT-2).
if offset%3600 == 0 {
hours := offset / 3600
if hours > 0 {
return fmt.Sprintf("Etc/GMT-%d", hours)
}
return fmt.Sprintf("Etc/GMT+%d", -hours)
}
return ""
}

Expand Down
3 changes: 2 additions & 1 deletion internal/cmd/calendar_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func TestExtractTimezone(t *testing.T) {
{"2026-01-08T16:00:00Z", "UTC"},
{"2026-01-08T11:00:00+00:00", "UTC"},
{"invalid", ""},
{"2026-01-08T11:00:00-04:00", ""}, // not a common US offset on this date
{"2026-01-08T11:00:00-04:00", "Etc/GMT+4"},
{"2026-01-08T11:00:00+02:00", "Etc/GMT-2"},
{"2026-01-08T11:00:00+05:30", ""}, // India - not mapped
}

Expand Down
57 changes: 57 additions & 0 deletions internal/cmd/calendar_create_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,63 @@ func TestCalendarCreateCmd_WithMeetAndAttachments(t *testing.T) {
}
}

func TestCalendarCreateCmd_RecurringOffsetTimezoneFallback(t *testing.T) {
origNew := newCalendarService
t.Cleanup(func() { newCalendarService = origNew })

var gotEvent calendar.Event
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/calendar/v3")
if r.Method == http.MethodPost && path == "/calendars/cal/events" {
_ = json.NewDecoder(r.Body).Decode(&gotEvent)
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]any{
"id": "ev3",
})
return
}
http.NotFound(w, r)
}))
defer srv.Close()

svc, err := calendar.NewService(context.Background(),
option.WithoutAuthentication(),
option.WithHTTPClient(srv.Client()),
option.WithEndpoint(srv.URL+"/"),
)
if err != nil {
t.Fatalf("NewService: %v", err)
}
newCalendarService = func(context.Context, string) (*calendar.Service, error) { return svc, nil }

u, err := ui.New(ui.Options{Stdout: os.Stdout, Stderr: os.Stderr, Color: "never"})
if err != nil {
t.Fatalf("ui.New: %v", err)
}
ctx := outfmt.WithMode(ui.WithUI(context.Background(), u), outfmt.Mode{JSON: true})

cmd := &CalendarCreateCmd{}
if err := runKong(t, cmd, []string{
"cal",
"--summary", "Recurring Test",
"--from", "2026-02-13T08:00:00+02:00",
"--to", "2026-02-13T09:00:00+02:00",
"--rrule", "FREQ=WEEKLY;BYDAY=TU,TH",
}, ctx, &RootFlags{Account: "a@b.com"}); err != nil {
t.Fatalf("runKong: %v", err)
}

if gotEvent.Start == nil || gotEvent.Start.TimeZone != "Etc/GMT-2" {
t.Fatalf("expected start timezone fallback Etc/GMT-2, got %#v", gotEvent.Start)
}
if gotEvent.End == nil || gotEvent.End.TimeZone != "Etc/GMT-2" {
t.Fatalf("expected end timezone fallback Etc/GMT-2, got %#v", gotEvent.End)
}
if len(gotEvent.Recurrence) == 0 {
t.Fatalf("expected recurrence to be set")
}
}

func TestCalendarUpdateCmd_RunJSON(t *testing.T) {
origNew := newCalendarService
t.Cleanup(func() { newCalendarService = origNew })
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/execute_drive_more_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func TestExecute_DriveMoreCommands_JSON(t *testing.T) {
})
return
case strings.Contains(path, "/files/id1") && r.Method == http.MethodDelete:
if got := r.URL.Query().Get("supportsAllDrives"); got != "true" {
t.Fatalf("expected supportsAllDrives=true, got: %q (raw=%q)", got, r.URL.RawQuery)
}
w.WriteHeader(http.StatusNoContent)
return
case strings.Contains(path, "/files/id1") && (r.Method == http.MethodPatch || r.Method == http.MethodPut):
Expand Down Expand Up @@ -224,6 +227,9 @@ func TestExecute_DriveMoreCommands_Text(t *testing.T) {
})
return
case strings.Contains(path, "/files/id1") && r.Method == http.MethodDelete:
if got := r.URL.Query().Get("supportsAllDrives"); got != "true" {
t.Fatalf("expected supportsAllDrives=true, got: %q (raw=%q)", got, r.URL.RawQuery)
}
w.WriteHeader(http.StatusNoContent)
return
case strings.Contains(path, "/files/id1") && (r.Method == http.MethodPatch || r.Method == http.MethodPut):
Expand Down
Loading