split limit determination into separate function
This commit is contained in:
parent
139bfff209
commit
1892e77e4f
19
main.go
19
main.go
|
@ -34,17 +34,23 @@ func formula(p float64) int64 {
|
|||
return int64(yearsAgo * 31556926)
|
||||
}
|
||||
|
||||
func (db *TimelineDB) closestEvents(t int64, n int, after bool, before bool) ([]EventsRow, error) {
|
||||
ulimit := int64(math.MaxInt64)
|
||||
func limits(t int64, after bool, before bool) (int64, int64, error) {
|
||||
llimit := int64(math.MinInt64)
|
||||
ulimit := int64(math.MaxInt64)
|
||||
var err error
|
||||
|
||||
if after && before {
|
||||
return nil, errors.New("after and before can't both be true")
|
||||
err = errors.New("after and before can't both be true")
|
||||
} else if after {
|
||||
llimit = t
|
||||
} else if before {
|
||||
ulimit = t
|
||||
}
|
||||
|
||||
return llimit, ulimit, err
|
||||
}
|
||||
|
||||
func (db *TimelineDB) closestEvents(t int64, n int, llimit int64, ulimit int64) ([]EventsRow, error) {
|
||||
query := `
|
||||
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
|
||||
from events
|
||||
|
@ -130,7 +136,12 @@ func main() {
|
|||
}
|
||||
defer db.Close()
|
||||
|
||||
events, err := db.closestEvents(t, *nevents, *after, *before)
|
||||
llimit, ulimit, err := limits(t, *after, *before)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
events, err := db.closestEvents(t, *nevents, llimit, ulimit)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue