add infra for unknown dates

This commit is contained in:
filifa 2024-03-19 20:31:32 -05:00
parent 1e49d6098c
commit a2f48ed7cc
2 changed files with 1980 additions and 1950 deletions

46
main.go
View File

@ -10,9 +10,21 @@ import (
"time"
)
type Event struct {
description string
timestamp int64
type EventsRow struct {
description sql.NullString
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 {
@ -20,10 +32,10 @@ func formula(p float64) int64 {
return int64(yearsAgo * 31556926)
}
func closestEvent(t int64, db *sql.DB) (Event, error) {
var event Event
func (db *TimelineDB) closestEvent(t int64) (EventsRow, error) {
var event EventsRow
query := `
select description, timestamp
select description, timestamp, yearknown, monthknown, dayknown, hourknown, minuteknown, secondknown
from events
where timestamp is not null
order by abs(? - timestamp) asc
@ -36,7 +48,7 @@ func closestEvent(t int64, db *sql.DB) (Event, error) {
}
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
}
@ -50,17 +62,29 @@ func main() {
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 {
log.Fatal(err)
}
defer db.Close()
event, err := closestEvent(t, db)
event, err := db.closestEvent(t)
if err != nil {
log.Fatal(err)
}
date := time.Unix(event.timestamp, 0)
fmt.Printf("%v\t%v\t%v\n", event.timestamp, date, event.description)
timestamp, err := event.timestamp.Value()
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)
}

File diff suppressed because it is too large Load Diff