bbgo: fix LooseFormatTime.UnmarshalYAML

This commit is contained in:
c9s 2022-01-25 01:18:50 +08:00
parent 8f0e80499b
commit a29198f733
2 changed files with 5 additions and 6 deletions

View File

@ -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)
},
},
}

View File

@ -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 {