1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-26 18:21:01 +00:00

refactor(reader): use time.Duration instead of minutes count

In general, duration is used as time unit representation.

At some places when int is returned, there's no documentation which unit is used.

So just convert to time.Duration ASAP.
This commit is contained in:
gudvinr 2025-08-18 23:10:18 +03:00 committed by Frédéric Guillot
parent 03021af53c
commit ed3bf59356
10 changed files with 144 additions and 104 deletions

View file

@ -67,11 +67,11 @@ func TestFeedCheckedNow(t *testing.T) {
}
}
func checkTargetInterval(t *testing.T, feed *Feed, targetInterval int, timeBefore time.Time, message string) {
if feed.NextCheckAt.Before(timeBefore.Add(time.Minute * time.Duration(targetInterval))) {
func checkTargetInterval(t *testing.T, feed *Feed, targetInterval time.Duration, timeBefore time.Time, message string) {
if feed.NextCheckAt.Before(timeBefore.Add(targetInterval)) {
t.Errorf(`The next_check_at should be after timeBefore + %s`, message)
}
if feed.NextCheckAt.After(time.Now().Add(time.Minute * time.Duration(targetInterval))) {
if feed.NextCheckAt.After(time.Now().Add(targetInterval)) {
t.Errorf(`The next_check_at should be before now + %s`, message)
}
}
@ -188,7 +188,7 @@ func TestFeedScheduleNextCheckRoundRobinMinInterval(t *testing.T) {
t.Error(`The next_check_at must be set`)
}
expectedInterval := minInterval
expectedInterval := time.Duration(minInterval) * time.Minute
checkTargetInterval(t, feed, expectedInterval, timeBefore, "TestFeedScheduleNextCheckRoundRobinMinInterval")
}
@ -217,7 +217,7 @@ func TestFeedScheduleNextCheckEntryFrequencyMaxInterval(t *testing.T) {
t.Error(`The next_check_at must be set`)
}
targetInterval := maxInterval
targetInterval := time.Duration(maxInterval) * time.Minute
checkTargetInterval(t, feed, targetInterval, timeBefore, "entry frequency max interval")
}
@ -246,7 +246,7 @@ func TestFeedScheduleNextCheckEntryFrequencyMaxIntervalZeroWeeklyCount(t *testin
t.Error(`The next_check_at must be set`)
}
targetInterval := maxInterval
targetInterval := time.Duration(maxInterval) * time.Minute
checkTargetInterval(t, feed, targetInterval, timeBefore, "entry frequency max interval")
}
@ -275,7 +275,7 @@ func TestFeedScheduleNextCheckEntryFrequencyMinInterval(t *testing.T) {
t.Error(`The next_check_at must be set`)
}
targetInterval := minInterval
targetInterval := time.Duration(minInterval) * time.Minute
checkTargetInterval(t, feed, targetInterval, timeBefore, "entry frequency min interval")
}
@ -301,7 +301,7 @@ func TestFeedScheduleNextCheckEntryFrequencyFactor(t *testing.T) {
t.Error(`The next_check_at must be set`)
}
targetInterval := config.Opts.SchedulerEntryFrequencyMaxInterval() / factor
targetInterval := config.Opts.SchedulerEntryFrequencyMaxInterval() / time.Duration(factor)
checkTargetInterval(t, feed, targetInterval, timeBefore, "factor * count")
}
@ -326,17 +326,17 @@ func TestFeedScheduleNextCheckEntryFrequencySmallNewTTL(t *testing.T) {
// Use a very large weekly count to trigger the min interval
weeklyCount := largeWeeklyCount
// TTL is smaller than minInterval.
newTTL := minInterval / 2
newTTL := time.Duration(minInterval) * time.Minute / 2
feed.ScheduleNextCheck(weeklyCount, newTTL)
if feed.NextCheckAt.IsZero() {
t.Error(`The next_check_at must be set`)
}
targetInterval := minInterval
targetInterval := time.Duration(minInterval) * time.Minute
checkTargetInterval(t, feed, targetInterval, timeBefore, "entry frequency min interval")
if feed.NextCheckAt.Before(timeBefore.Add(time.Minute * time.Duration(newTTL))) {
if feed.NextCheckAt.Before(timeBefore.Add(newTTL)) {
t.Error(`The next_check_at should be after timeBefore + TTL`)
}
}
@ -362,7 +362,7 @@ func TestFeedScheduleNextCheckEntryFrequencyLargeNewTTL(t *testing.T) {
// Use a very large weekly count to trigger the min interval
weeklyCount := largeWeeklyCount
// TTL is larger than minInterval.
newTTL := minInterval * 2
newTTL := time.Duration(minInterval) * time.Minute * 2
feed.ScheduleNextCheck(weeklyCount, newTTL)
if feed.NextCheckAt.IsZero() {