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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 0.48.1 - Unreleased

- Calendar: give recurring `calendar create` and `calendar focus-time` events the calendar's time zone when `--from`/`--to` carry only an offset that matches it, so a weekly `-08:00` series stays at its local time after daylight saving starts instead of following a fixed `Etc/GMT+8` zone, and a `+05:30` series is accepted instead of failing with "Missing time zone definition". Offsets that match no zone the calendar uses keep their previous handling; an unmatched half-hour offset in `calendar create` now asks for `--timezone` (or `--start-timezone`/`--end-timezone` when one endpoint already has its own zone) before the event is created. (#1310) — thanks @saariuslystoned.

## 0.48.0 - 2026-11-05

**Highlights:** New backups stay local until you configure a remote; existing configurations keep working. Store service-account keys in the keyring, search Gmail IDs efficiently, and use environment-backed watch tokens, with Calendar fixes and security dependency updates.
Expand Down
6 changes: 6 additions & 0 deletions docs/dates.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ Tracking `--since` also accepts `time.ParseDuration` values such as:
- Generate RFC3339 for all datetime fields by default.
- Use date-only for fields explicitly documented as dates.
- For local scheduling, pass an explicit offset (or timezone-aware RFC3339) to avoid ambiguity.
- Recurring Calendar events repeat in one IANA time zone. When `calendar create`
or `calendar focus-time` gets `--rrule` with times that carry only an offset,
gog uses the calendar's time zone if it has that offset at the given time, so
the series keeps its local time across daylight saving changes. Other offsets
keep a fixed `Etc/GMT` zone, and UTC times stay in UTC. Pass `--timezone` to
choose the zone yourself.
99 changes: 99 additions & 0 deletions internal/cmd/calendar_build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"regexp"
"strconv"
Expand Down Expand Up @@ -103,6 +104,104 @@ func extractTimezone(value string) string {
return ""
}

// applyRecurringCalendarTimezone sets the zone Google expands a recurring
// series in when --from or --to carries only a UTC offset. An offset alone maps
// to a fixed Etc/GMT zone, which keeps the series on that offset across
// daylight saving changes, and half-hour offsets have no Etc/GMT zone at all.
// The calendar's own zone is used when it has the same offset at that time.
// Explicit timezones, UTC times and all-day dates are kept as given. When
// timezoneFlag is set, an offset that still has no zone is a usage error that
// names the flag, instead of a request Google rejects.
func applyRecurringCalendarTimezone(ctx context.Context, mutation *calendarMutationContext, event *calendar.Event, startTimezone, endTimezone, timezoneFlag string) error {
if event == nil || len(event.Recurrence) == 0 {
return nil
}
start := recurringZoneFromOffset(event.Start, startTimezone)
end := recurringZoneFromOffset(event.End, endTimezone)
if !start && !end {
return nil
}
calendarTimezone, calendarLoc := mutation.calendarLocation(ctx)
// --timezone cannot be combined with the per-endpoint flags, so once one
// endpoint has its own zone, point the other at its own flag.
startFlag, endFlag := timezoneFlag, timezoneFlag
if timezoneFlag != "" && (strings.TrimSpace(startTimezone) != "" || strings.TrimSpace(endTimezone) != "") {
startFlag, endFlag = "--start-timezone", "--end-timezone"
}
if start {
if err := applyCalendarZoneForOffset(event.Start, calendarTimezone, calendarLoc, "--from", startFlag); err != nil {
return err
}
}
if end {
if err := applyCalendarZoneForOffset(event.End, calendarTimezone, calendarLoc, "--to", endFlag); err != nil {
return err
}
}
return nil
}

// recurringTimezoneLookupPlan describes, for --dry-run, the calendar time zone
// lookup applyRecurringCalendarTimezone makes when the command runs. Dry runs
// stay offline, so the event they show carries the fallback zone.
func recurringTimezoneLookupPlan(event *calendar.Event, startTimezone, endTimezone, unmatched string) map[string]any {
if event == nil || len(event.Recurrence) == 0 {
return nil
}
out := map[string]any{}
for _, side := range []struct {
key string
dt *calendar.EventDateTime
explicit string
}{{"start", event.Start, startTimezone}, {"end", event.End, endTimezone}} {
if !recurringZoneFromOffset(side.dt, side.explicit) {
continue
}
t, err := time.Parse(time.RFC3339, strings.TrimSpace(side.dt.DateTime))
if err != nil {
continue
}
entry := map[string]any{
"offset": t.Format("-07:00"),
"rule": "use the calendar's time zone if it has this offset at dateTime",
}
if side.dt.TimeZone != "" {
entry["fallback_timezone"] = side.dt.TimeZone
} else {
entry["fallback"] = unmatched
}
out[side.key] = entry
}
if len(out) == 0 {
return nil
}
return out
}

func recurringZoneFromOffset(dt *calendar.EventDateTime, explicitTimezone string) bool {
return dt != nil && strings.TrimSpace(explicitTimezone) == "" &&
strings.TrimSpace(dt.DateTime) != "" && dt.TimeZone != tzUTC
}

func applyCalendarZoneForOffset(dt *calendar.EventDateTime, calendarTimezone string, calendarLoc *time.Location, flagName, timezoneFlag string) error {
t, parseErr := time.Parse(time.RFC3339, strings.TrimSpace(dt.DateTime))
if parseErr != nil {
// Not an RFC3339 instant: leave the zone to the existing handling.
return nil //nolint:nilerr // an unparsable time is not this helper's error to report
}
_, offset := t.Zone()
if calendarLoc != nil {
if _, calendarOffset := t.In(calendarLoc).Zone(); calendarOffset == offset {
dt.TimeZone = calendarTimezone
return nil
}
}
if dt.TimeZone == "" && timezoneFlag != "" {
return usagef("recurring events need an IANA time zone: %s offset %s has no fixed-offset zone and does not match the calendar's time zone; pass %s with an IANA zone name", flagName, t.Format("-07:00"), timezoneFlag)
}
return nil
}

type conferenceChoice struct {
provider string
}
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/calendar_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ func (c *CalendarCreateCmd) Run(ctx context.Context, flags *RootFlags, kctx *kon
if err != nil {
return err
}
if tzErr := applyRecurringCalendarTimezone(ctx, mutation, plan.Event, plan.StartTimezone, plan.EndTimezone, flagTimezone); tzErr != nil {
return tzErr
}

var zoomMeeting *zoom.Meeting
if plan.WithZoom {
Expand Down
25 changes: 19 additions & 6 deletions internal/cmd/calendar_event_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ type calendarCreatePlan struct {
WithZoom bool
PlaceLookup *calendarPlaceLookupRequest
Event *calendar.Event
// StartTimezone and EndTimezone are the explicit timezone flags in effect
// (--timezone applies to both); empty means the zone came from the offset.
StartTimezone string
EndTimezone string
}

type calendarUpdateFields struct {
Expand Down Expand Up @@ -415,12 +419,14 @@ func buildCalendarCreatePlan(store *config.ConfigStore, input calendarCreateInpu
}

return &calendarCreatePlan{
CalendarID: calendarID,
SendUpdates: sendUpdates,
WithMeet: input.WithMeet,
WithZoom: input.WithZoom,
PlaceLookup: placeLookup,
Event: event,
CalendarID: calendarID,
SendUpdates: sendUpdates,
WithMeet: input.WithMeet,
WithZoom: input.WithZoom,
PlaceLookup: placeLookup,
Event: event,
StartTimezone: startTZ,
EndTimezone: endTZ,
}, nil
}

Expand All @@ -438,6 +444,13 @@ func (p *calendarCreatePlan) dryRunRequest() map[string]any {
if p.PlaceLookup != nil {
request["place_lookup"] = p.PlaceLookup.dryRunPayload()
}
unmatched := "usage error asking for --timezone"
if strings.TrimSpace(p.StartTimezone) != "" || strings.TrimSpace(p.EndTimezone) != "" {
unmatched = "usage error asking for --start-timezone or --end-timezone"
}
if lookup := recurringTimezoneLookupPlan(p.Event, p.StartTimezone, p.EndTimezone, unmatched); lookup != nil {
request["recurring_timezone_lookup"] = lookup
}
return request
}

Expand Down
11 changes: 9 additions & 2 deletions internal/cmd/calendar_focus_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,24 @@ func (c *CalendarFocusTimeCmd) Run(ctx context.Context, flags *RootFlags) error
Recurrence: buildRecurrence(c.Recurrence),
}

if dryRunErr := dryRunExit(ctx, flags, "calendar.focus-time", map[string]any{
dryRun := map[string]any{
"calendar_id": calendarID,
"event": event,
}); dryRunErr != nil {
}
if lookup := recurringTimezoneLookupPlan(event, "", "", "no time zone is sent"); lookup != nil {
dryRun["recurring_timezone_lookup"] = lookup
}
if dryRunErr := dryRunExit(ctx, flags, "calendar.focus-time", dryRun); dryRunErr != nil {
return dryRunErr
}

mutation, err := newCalendarMutationContext(ctx, flags, calendarID)
if err != nil {
return err
}
if tzErr := applyRecurringCalendarTimezone(ctx, mutation, event, "", "", ""); tzErr != nil {
return tzErr
}

created, err := mutation.insertEvent(ctx, event, calendarInsertOptions{})
if err != nil {
Expand Down
17 changes: 16 additions & 1 deletion internal/cmd/calendar_mutation_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"time"

"google.golang.org/api/calendar/v3"

Expand All @@ -13,6 +14,20 @@ type calendarMutationContext struct {
u *ui.UI
svc *calendar.Service
calendarID string

timezoneLoaded bool
timezone string
location *time.Location
}

// calendarLocation returns the calendar's time zone, fetched once per command.
// An empty zone and nil location mean the lookup failed.
func (m *calendarMutationContext) calendarLocation(ctx context.Context) (string, *time.Location) {
if !m.timezoneLoaded {
m.timezone, m.location, _ = getCalendarLocation(ctx, m.svc, m.calendarID)
m.timezoneLoaded = true
}
return m.timezone, m.location
}

type calendarInsertOptions struct {
Expand Down Expand Up @@ -98,7 +113,7 @@ func (m *calendarMutationContext) moveEvent(ctx context.Context, eventID, destin

func (m *calendarMutationContext) writeEvent(ctx context.Context, event *calendar.Event) error {
redactCalendarEventForOutput(ctx, event)
tz, loc, _ := getCalendarLocation(ctx, m.svc, m.calendarID)
tz, loc := m.calendarLocation(ctx)
if outfmt.IsJSON(ctx) {
return outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{"event": wrapEventWithDaysWithTimezone(event, tz, loc)})
}
Expand Down
Loading
Loading