Skip to content

Commit

Permalink
bbgo: fix LooseFormatTime.UnmarshalYAML
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Jan 24, 2022
1 parent 8f0e804 commit a29198f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion pkg/bbgo/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func TestLoadConfig(t *testing.T) {
assert.NotNil(t, config.Backtest.Account)
assert.NotNil(t, config.Backtest.Account.Balances)
assert.Len(t, config.Backtest.Account.Balances, 2)
assert.NotEmpty(t, config.Backtest.StartTime)
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/types/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,17 @@ type LooseFormatTime time.Time

func (t *LooseFormatTime) UnmarshalYAML(unmarshal func(interface{}) error) error {
var str string
if err := unmarshal(&str); err == nil {
return t.UnmarshalJSON([]byte(str))
if err := unmarshal(&str); err != nil {
return err
}

var bin []byte
err := unmarshal(&bin)
tv, err := util.ParseTimeWithFormats(str, looseTimeFormats)
if err != nil {
return err
}

return t.UnmarshalJSON(bin)
*t = LooseFormatTime(tv)
return nil
}

func (t *LooseFormatTime) UnmarshalJSON(data []byte) error {
Expand Down

0 comments on commit a29198f

Please sign in to comment.