-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.go
More file actions
34 lines (30 loc) · 766 Bytes
/
time.go
File metadata and controls
34 lines (30 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package bgen
import (
"fmt"
"time"
)
// Time exists to facilitate time parsing from the Metadata, because BGEN
// uses both unixtime and text strings to represent time. Derived from
// https://github.com/mattn/go-sqlite3/issues/190#issuecomment-343341834f
type Time time.Time
func (t *Time) Scan(v interface{}) error {
switch which := v.(type) {
case int64:
vt := time.Unix(which, 0)
*t = Time(vt)
return nil
case int:
vt := time.Unix(int64(which), 0)
*t = Time(vt)
return nil
case []byte:
// Should be more strictly to check this type.
vt, err := time.Parse("2006-01-02 15:04:05", string(which))
if err != nil {
return err
}
*t = Time(vt)
return nil
}
return fmt.Errorf("No appropriate type could be found to decode %v", v)
}