Files
x-realy/timestamp/timestamp.go
mleku d5ae20ba94 Refactor timestamp handling to use integers directly.
Replaced `FromInt64` with `FromInt` to simplify timestamp operations. Updated related methods, tests, and logic to consistently handle timestamps as integers, improving code clarity and reducing unnecessary conversions.
2025-06-14 09:08:20 +01:00

20 lines
429 B
Go

package timestamp
import (
"time"
"golang.org/x/exp/constraints"
)
type Timestamp int64
func Now() Timestamp { return Timestamp(time.Now().Unix()) }
func New[T constraints.Integer | constraints.Float](t T) Timestamp {
return Timestamp(t)
}
func (t Timestamp) Time() time.Time { return time.Unix(int64(t), 0) }
func (t Timestamp) ToInt64() int64 { return int64(t) }
func (t Timestamp) ToInt() int { return int(t) }