25 lines
505 B
Go
25 lines
505 B
Go
package proto
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/golang/protobuf/ptypes/timestamp"
|
|
)
|
|
|
|
// Converts time.Time (ptr AND value) to *timestamp.Timestamp
|
|
//
|
|
// Intentionally ignoring
|
|
func fromTime(i interface{}) *timestamp.Timestamp {
|
|
switch t := i.(type) {
|
|
case *time.Time:
|
|
if t == nil {
|
|
return nil
|
|
}
|
|
return ×tamp.Timestamp{Seconds: t.Unix(), Nanos: int32(t.Nanosecond())}
|
|
case time.Time:
|
|
return ×tamp.Timestamp{Seconds: t.Unix(), Nanos: int32(t.Nanosecond())}
|
|
default:
|
|
return nil
|
|
}
|
|
}
|