parent
bdc99a3c5e
commit
23606cd501
|
@ -3,3 +3,4 @@ twtxt
|
|||
worker
|
||||
nimcache
|
||||
*.db
|
||||
*.so
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
gotime.so
|
||||
gotime.h
|
|
@ -0,0 +1,23 @@
|
|||
import times
|
||||
|
||||
proc fixTime(p0: cstring): ptr clonglong {. importc, dynlib: "./gotime.so", noSideEffect .}
|
||||
|
||||
proc parseTime*(inp: string): TimeInfo =
|
||||
let
|
||||
cst = inp.cstring
|
||||
res = cst.fixTime
|
||||
|
||||
if res == nil:
|
||||
raise newException(ValueError, "Invalid time passed to this thing")
|
||||
|
||||
return res[].fromSeconds.timeToTimeInfo
|
||||
|
||||
when isMainModule:
|
||||
let myTime = fixTime("2006-01-02T15:04:05.000000-07:00")
|
||||
|
||||
if myTime == nil:
|
||||
quit "lol failed"
|
||||
|
||||
echo myTime[]
|
||||
|
||||
echo parseTime("2006-01-02T15:04:05-07:00")
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
import "C"
|
||||
|
||||
//export fixTime
|
||||
func fixTime(inp *C.char) *int64 {
|
||||
gostr := C.GoString(inp)
|
||||
|
||||
t, err := time.Parse("2006-01-02T15:04:05.000000-07:00", gostr)
|
||||
if err != nil {
|
||||
t, err = time.Parse("2006-01-02T15:04:05-07:00", gostr)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
res := t.Unix()
|
||||
|
||||
return &res
|
||||
}
|
||||
|
||||
func main() {}
|
|
@ -1,4 +1,4 @@
|
|||
import db_sqlite, json, httpclient, os, strutils, times
|
||||
import db_sqlite, json, httpclient, os, strutils, times, time/gotime
|
||||
|
||||
const
|
||||
ISOTime*: string = "yyyy-MM-dd'T'HH:mm:ss'.000000'zzz"
|
||||
|
@ -34,7 +34,7 @@ proc parseTweet*(user, inp: string): Tweet =
|
|||
raise newException(ValueError, "Invalid tweet")
|
||||
|
||||
let
|
||||
tdate = splitTweet[0].parse(ISOTime)
|
||||
tdate = splitTweet[0].parseTime
|
||||
message = splitTweet[1]
|
||||
|
||||
Tweet(date: tdate,
|
||||
|
|
|
@ -16,6 +16,12 @@ mode = ScriptMode.Verbose
|
|||
task db, "SQLite database prompt":
|
||||
exec "sqlite3 data/twtxt.db"
|
||||
|
||||
task godep, "build go deps":
|
||||
withDir "src/time":
|
||||
exec "go build -buildmode=c-shared -o gotime.so time.go"
|
||||
exec "cp gotime.so ../.."
|
||||
|
||||
task run, "Run app":
|
||||
exec "nimble build"
|
||||
exec "nimble godep"
|
||||
exec "./twtxtlist"
|
||||
|
|
Loading…
Reference in New Issue