Source File
time.go
Belonging Package
github.com/jackc/pgtype
package pgtype
import (
)
type Time struct {
Microseconds int64 // Number of microseconds since midnight
Status Status
}
func ( *Time) ( interface{}) error {
if == nil {
* = Time{Status: Null}
return nil
}
if , := .(interface{ () interface{} }); {
:= .()
if != {
return .()
}
}
switch value := .(type) {
case time.Time:
:= int64(.Hour())*microsecondsPerHour +
int64(.Minute())*microsecondsPerMinute +
int64(.Second())*microsecondsPerSecond +
int64(.Nanosecond())/1000
* = Time{Microseconds: , Status: Present}
case *time.Time:
if == nil {
* = Time{Status: Null}
} else {
return .(*)
}
default:
if , := underlyingTimeType(); {
return .()
}
return fmt.Errorf("cannot convert %v to Time", )
}
return nil
}
func ( Time) () interface{} {
switch .Status {
case Present:
return .Microseconds
case Null:
return nil
default:
return .Status
}
}
func ( *Time) ( interface{}) error {
switch .Status {
case Present:
switch v := .(type) {
var int64 = 24*60*60*1000000 - 1
if .Microseconds > {
return fmt.Errorf("%d microseconds cannot be represented as time.Time", .Microseconds)
}
:= .Microseconds
:= / microsecondsPerHour
-= * microsecondsPerHour
:= / microsecondsPerMinute
-= * microsecondsPerMinute
:= / microsecondsPerSecond
-= * microsecondsPerSecond
:= * 1000
* = time.Date(2000, 1, 1, int(), int(), int(), int(), time.UTC)
return nil
default:
if , := GetAssignToDstType(); {
return .()
}
return fmt.Errorf("unable to assign to %T", )
}
case Null:
return NullAssignTo()
}
return fmt.Errorf("cannot decode %#v into %T", , )
}
func ( *Time) ( *ConnInfo, []byte) error {
if == nil {
* = Time{Status: Null}
return nil
}
:= string()
if len() < 8 {
return fmt.Errorf("cannot decode %v into Time", )
}
, := strconv.ParseInt([0:2], 10, 64)
if != nil {
return fmt.Errorf("cannot decode %v into Time", )
}
:= * microsecondsPerHour
, := strconv.ParseInt([3:5], 10, 64)
if != nil {
return fmt.Errorf("cannot decode %v into Time", )
}
+= * microsecondsPerMinute
, := strconv.ParseInt([6:8], 10, 64)
if != nil {
return fmt.Errorf("cannot decode %v into Time", )
}
+= * microsecondsPerSecond
if len() > 9 {
:= [9:]
, := strconv.ParseInt(, 10, 64)
if != nil {
return fmt.Errorf("cannot decode %v into Time", )
}
for := len(); < 6; ++ {
*= 10
}
+=
}
* = Time{Microseconds: , Status: Present}
return nil
}
func ( Time) ( *ConnInfo, []byte) ([]byte, error) {
switch .Status {
case Null:
return nil, nil
case Undefined:
return nil, errUndefined
}
:= .Microseconds
:= / microsecondsPerHour
-= * microsecondsPerHour
:= / microsecondsPerMinute
-= * microsecondsPerMinute
:= / microsecondsPerSecond
-= * microsecondsPerSecond
:= fmt.Sprintf("%02d:%02d:%02d.%06d", , , , )
return append(, ...), nil
}
func ( Time) () (driver.Value, error) {
return EncodeValueText()
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |