twtxtlist/src/time/gotime.nim

24 lines
517 B
Nim

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")