Skip to content

Commit

Permalink
Also accept parts of "today" string for quicker recording
Browse files Browse the repository at this point in the history
Solves #14
  • Loading branch information
LucaBernstein committed Nov 4, 2021
1 parent cdc51d3 commit 6c043bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bot/transactionBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func HandleRaw(m *tb.Message) (string, error) {

func HandleDate(m *tb.Message) (string, error) {
// Handle "today" string
if strings.TrimSpace(strings.ToLower(m.Text)) == "today" {

if strings.HasPrefix("today", strings.TrimSpace(strings.ToLower(m.Text))) {
return time.Now().Format(BEANCOUNT_DATE_FORMAT), nil
}
// Handle YYYY-MM-DD
Expand Down
20 changes: 19 additions & 1 deletion bot/transactionBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,25 @@ func TestCountLeadingDigits(t *testing.T) {
func TestDateSpecialNow(t *testing.T) {
h, err := bot.HandleDate(&tb.Message{Text: " ToDaY "})
if err != nil {
t.Errorf("There should be no error handling date 'now': %s", err.Error())
t.Errorf("There should be no error handling date 'today': %s", err.Error())
}
helpers.TestExpect(t, h, time.Now().Format("2006-01-02"), "")

// GitHub-Issue #14: Also accept parts of "today" string for quicker recording
h, err = bot.HandleDate(&tb.Message{Text: " t"})
if err != nil {
t.Errorf("There should be no error handling date 't': %s", err.Error())
}
helpers.TestExpect(t, h, time.Now().Format("2006-01-02"), "")

h, err = bot.HandleDate(&tb.Message{Text: " tod"})
if err != nil {
t.Errorf("There should be no error handling date 'tod': %s", err.Error())
}
helpers.TestExpect(t, h, time.Now().Format("2006-01-02"), "")

_, err = bot.HandleDate(&tb.Message{Text: "tomorrow"})
if err == nil {
t.Errorf("There should be an error processing the date 'tomorrow': %s", err.Error())
}
}

0 comments on commit 6c043bd

Please sign in to comment.