Skip to content
Merged
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: 3 additions & 7 deletions internal/tui/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,16 @@ func (p *dateTimePicker) handleKey(msg tea.KeyPressMsg) tea.Cmd {
}
}

// dateStep is the day-at-a-time keys. The arrows are unbound in a single-line text input,
// and a + cannot appear in YYYY-MM-DD, so typing one is only ever a step. A - is the date's
// own separator, so it is typed into the field like any other character (hey-cli#368).
// dateStep is the day-at-a-time keys: the arrows, which are unbound in a single-line text
// input. Nothing printable steps, because a date is typed as YYYY-MM-DD and every key that
// can appear in one has to reach the input — a - that stepped instead could never be typed.
func dateStep(msg tea.KeyPressMsg) (days int, stepped bool) {
switch msg.Key().Code {
case tea.KeyUp:
return 1, true
case tea.KeyDown:
return -1, true
}
switch msg.String() {
case "+", "=":
return 1, true
}
return 0, false
}

Expand Down
18 changes: 16 additions & 2 deletions internal/tui/datetime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func TestDateTimePickerStepsTheDateByADay(t *testing.T) {
t.Errorf("after two downs, date() = %q, want 2026-08-21", got)
}

typeInto(t, picker, "+")
picker.handleKey(tea.KeyPressMsg{Code: tea.KeyUp})
if got := picker.date(); got != "2026-08-22" {
t.Errorf("after +, date() = %q, want 2026-08-22", got)
t.Errorf("after up, date() = %q, want 2026-08-22", got)
}

picker.dateInput.SetValue("next tuesday")
Expand All @@ -97,6 +97,20 @@ func TestDateTimePickerTypesTheDateSeparator(t *testing.T) {
}
}

func TestDateTimePickerTypesADateWithItsHyphens(t *testing.T) {
picker := testPicker()
picker.focusFirst()
picker.dateInput.SetValue("")

typeInto(t, picker, "2026-09-14")
if got := picker.date(); got != "2026-09-14" {
t.Errorf("after typing 2026-09-14, date() = %q", got)
}
if got := picker.problem(); got != "" {
t.Errorf("problem() = %q, want none for a typed date", got)
}
}

func TestDateTimePickerAllDayHidesTheTimeAndTheZone(t *testing.T) {
picker := testPicker()
picker.setZoneName("Europe/Zagreb")
Expand Down
Loading