refactor: add IsOver to check the since time is over given duration

This commit is contained in:
narumi 2023-08-31 14:30:50 +08:00
parent 2c4b6e8cd1
commit 52412d9ead

View File

@ -240,9 +240,14 @@ func (s *ProfitStats) AddTrade(trade Trade) {
s.AccumulatedVolume = s.AccumulatedVolume.Add(trade.Quantity) s.AccumulatedVolume = s.AccumulatedVolume.Add(trade.Quantity)
} }
// IsOver checks if the since time is over given duration
func (s *ProfitStats) IsOver(d time.Duration) bool {
return time.Since(time.Unix(s.TodaySince, 0)) >= d
}
// IsOver24Hours checks if the since time is over 24 hours // IsOver24Hours checks if the since time is over 24 hours
func (s *ProfitStats) IsOver24Hours() bool { func (s *ProfitStats) IsOver24Hours() bool {
return time.Since(time.Unix(s.TodaySince, 0)) >= 24*time.Hour return s.IsOver(24 * time.Hour)
} }
func (s *ProfitStats) ResetToday(t time.Time) { func (s *ProfitStats) ResetToday(t time.Time) {