service backend
All checks were successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful

This commit is contained in:
Stephan D
2025-11-07 18:35:26 +01:00
parent 20e8f9acc4
commit 62a6631b9a
537 changed files with 48453 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
package timeutil
import (
"time"
"google.golang.org/protobuf/types/known/timestamppb"
)
// UnixMilliToTime converts Unix milliseconds to time.Time
func UnixMilliToTime(ms int64) time.Time {
return time.Unix(0, ms*int64(time.Millisecond))
}
// TimeToUnixMilli converts time.Time to Unix milliseconds
func TimeToUnixMilli(t time.Time) int64 {
return t.UnixMilli()
}
// ProtoToTime converts a protobuf Timestamp to time.Time
// Returns zero time if timestamp is nil
func ProtoToTime(ts *timestamppb.Timestamp) time.Time {
if ts == nil {
return time.Time{}
}
return ts.AsTime()
}
// TimeToProto converts time.Time to protobuf Timestamp
// Returns nil for zero time
func TimeToProto(t time.Time) *timestamppb.Timestamp {
if t.IsZero() {
return nil
}
return timestamppb.New(t)
}
// NowProto returns current time as protobuf Timestamp
func NowProto() *timestamppb.Timestamp {
return timestamppb.Now()
}