add infra for unknown dates
This commit is contained in:
parent
990c9a66bd
commit
1ecf16bd0a
46
main.go
46
main.go
|
@ -10,9 +10,21 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type EventsRow struct {
|
||||||
description string
|
description sql.NullString
|
||||||
timestamp int64
|
timestamp sql.NullInt64
|
||||||
|
interval sql.NullString
|
||||||
|
period sql.NullString
|
||||||
|
yearknown sql.NullBool
|
||||||
|
monthknown sql.NullBool
|
||||||
|
dayknown sql.NullBool
|
||||||
|
hourknown sql.NullBool
|
||||||
|
minuteknown sql.NullBool
|
||||||
|
secondknown sql.NullBool
|
||||||
|
}
|
||||||
|
|
||||||
|
type TimelineDB struct {
|
||||||
|
*sql.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func formula(p float64) int64 {
|
func formula(p float64) int64 {
|
||||||
|
@ -20,10 +32,10 @@ func formula(p float64) int64 {
|
||||||
return int64(yearsAgo * 31556926)
|
return int64(yearsAgo * 31556926)
|
||||||
}
|
}
|
||||||
|
|
||||||
func closestEvent(t int64, db *sql.DB) (Event, error) {
|
func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
|
||||||
var event Event
|
var event EventsRow
|
||||||
query := `
|
query := `
|
||||||
select description, timestamp
|
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
|
||||||
from events
|
from events
|
||||||
where timestamp is not null
|
where timestamp is not null
|
||||||
order by abs(? - timestamp) asc
|
order by abs(? - timestamp) asc
|
||||||
|
@ -36,7 +48,7 @@ func closestEvent(t int64, db *sql.DB) (Event, error) {
|
||||||
}
|
}
|
||||||
defer stmt.Close()
|
defer stmt.Close()
|
||||||
|
|
||||||
err = stmt.QueryRow(t).Scan(&event.description, &event.timestamp)
|
err = stmt.QueryRow(t).Scan(&event.description, &event.timestamp, &event.yearknown, &event.monthknown, &event.dayknown, &event.hourknown, &event.minuteknown, &event.secondknown)
|
||||||
return event, err
|
return event, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,17 +62,29 @@ func main() {
|
||||||
|
|
||||||
t := time.Now().Unix() - formula(*percent)
|
t := time.Now().Unix() - formula(*percent)
|
||||||
|
|
||||||
db, err := sql.Open("sqlite3", "./timeline.db")
|
var db TimelineDB
|
||||||
|
var err error
|
||||||
|
db.DB, err = sql.Open("sqlite3", "./timeline.db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
event, err := closestEvent(t, db)
|
event, err := db.closestEvent(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
date := time.Unix(event.timestamp, 0)
|
timestamp, err := event.timestamp.Value()
|
||||||
fmt.Printf("%v\t%v\t%v\n", event.timestamp, date, event.description)
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
desc, err := event.description.Value()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
date := time.Unix(timestamp.(int64), 0)
|
||||||
|
fmt.Printf("%v\t%v\t%v\n", timestamp, date, desc)
|
||||||
}
|
}
|
||||||
|
|
3884
timeline.sql
3884
timeline.sql
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue