move limits logic to main
This commit is contained in:
parent
1892e77e4f
commit
270bf73b4d
35
main.go
35
main.go
|
@ -34,22 +34,6 @@ func formula(p float64) int64 {
|
||||||
return int64(yearsAgo * 31556926)
|
return int64(yearsAgo * 31556926)
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
|
||||||
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) {
|
func (db *TimelineDB) closestEvents(t int64, n int, llimit int64, ulimit int64) ([]EventsRow, error) {
|
||||||
query := `
|
query := `
|
||||||
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
|
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
|
||||||
|
@ -116,10 +100,6 @@ func main() {
|
||||||
before := flag.Bool("b", false, "only return events occurring before computed timestamp")
|
before := flag.Bool("b", false, "only return events occurring before computed timestamp")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *after && *before {
|
|
||||||
log.Fatal("cannot pass both -a and -b")
|
|
||||||
}
|
|
||||||
|
|
||||||
if *percent < 0 || *percent > 1 {
|
if *percent < 0 || *percent > 1 {
|
||||||
log.Fatal("invalid percentage")
|
log.Fatal("invalid percentage")
|
||||||
} else if *nevents < 0 {
|
} else if *nevents < 0 {
|
||||||
|
@ -128,6 +108,16 @@ func main() {
|
||||||
|
|
||||||
t := time.Now().Unix() - formula(*percent)
|
t := time.Now().Unix() - formula(*percent)
|
||||||
|
|
||||||
|
llimit := int64(math.MinInt64)
|
||||||
|
ulimit := int64(math.MaxInt64)
|
||||||
|
if *after && *before {
|
||||||
|
log.Fatal("cannot pass both -a and -b")
|
||||||
|
} else if *after {
|
||||||
|
llimit = t
|
||||||
|
} else if *before {
|
||||||
|
ulimit = t
|
||||||
|
}
|
||||||
|
|
||||||
var db TimelineDB
|
var db TimelineDB
|
||||||
var err error
|
var err error
|
||||||
db.DB, err = sql.Open("sqlite3", "./timeline.db")
|
db.DB, err = sql.Open("sqlite3", "./timeline.db")
|
||||||
|
@ -136,11 +126,6 @@ func main() {
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
llimit, ulimit, err := limits(t, *after, *before)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
events, err := db.closestEvents(t, *nevents, llimit, ulimit)
|
events, err := db.closestEvents(t, *nevents, llimit, ulimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
|
Loading…
Reference in New Issue