Skip to content

Commit

Permalink
Merge pull request #33 from rusq/i28
Browse files Browse the repository at this point in the history
Fix timestamp parsing in TimeValue
  • Loading branch information
rusq authored Feb 22, 2022
2 parents f228fd4 + 2af06ec commit 5cd5076
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ func (app *App) saveText(filename string, m *slackdump.Conversation) error {
return m.ToText(app.sd, f)
}

// listEntities queries lists the supported entities, and writes the output to output.
// listEntities queries lists the supported entities, and writes the output to
// the output defined in the app.cfg.
func (app *App) listEntities(ctx context.Context) error {
f, err := createFile(app.cfg.Output.Filename)
if err != nil {
Expand Down Expand Up @@ -207,7 +208,7 @@ func (app *App) fetchEntity(ctx context.Context, listFlags ListFlags) (rep slack
return
}

// formatEntity formats the entity according to output specification.
// formatEntity formats the entity according to output parameter value.
func (app *App) formatEntity(w io.Writer, rep slackdump.Reporter, output Output) error {
switch output.Format {
case OutputTypeText:
Expand Down
2 changes: 1 addition & 1 deletion internal/app/timevalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (tv *TimeValue) Set(s string) error {
if s == "" {
return nil
}
if t, err := time.Parse(s, timeFmt); err != nil {
if t, err := time.Parse(timeFmt, s); err != nil {
return err
} else {
*tv = TimeValue(t)
Expand Down
43 changes: 43 additions & 0 deletions internal/app/timevalue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package app

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func tv(t time.Time) *TimeValue {
tv := TimeValue(t)
return &tv
}

func TestTimeValue_Set(t *testing.T) {
type args struct {
s string
}
tests := []struct {
name string
tv *TimeValue
args args
wantTime *TimeValue
wantErr bool
}{
{
"valid value",
&TimeValue{},
args{"2009-09-16T20:30:40"},
tv(time.Date(2009, 9, 16, 20, 30, 40, 0, time.UTC)),
false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tv := &TimeValue{}
if err := tv.Set(tt.args.s); (err != nil) != tt.wantErr {
t.Errorf("TimeValue.Set() error = %v, wantErr %v", err, tt.wantErr)
}
assert.Equal(t, tt.wantTime, tv)
})
}
}

0 comments on commit 5cd5076

Please sign in to comment.