Time !
This commit is contained in:
34
model/time.go
Normal file
34
model/time.go
Normal file
@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
"errors"
|
||||
sqldriver "database/sql/driver"
|
||||
)
|
||||
|
||||
type Time time.Time
|
||||
|
||||
func MakeTimeNow() Time {
|
||||
return Time(time.Now().UTC())
|
||||
}
|
||||
|
||||
func (self Time) String() string {
|
||||
return time.Time(self).String()
|
||||
}
|
||||
|
||||
func (self Time) Value() (sqldriver.Value, error) {
|
||||
return time.Time(self).Format(time.RFC3339), nil
|
||||
}
|
||||
|
||||
func (self *Time) Scan(value any) error {
|
||||
if valueStr, ok := value.(string); ok {
|
||||
parsedTime, err := time.Parse(time.RFC3339, valueStr)
|
||||
if err == nil {
|
||||
*self = Time(parsedTime.UTC())
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
return errors.New("Expected a string")
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package model
|
||||
|
||||
type Timer struct {
|
||||
Id UUID
|
||||
Name string
|
||||
Id UUID
|
||||
Name string
|
||||
StartTime Time
|
||||
EndTime Time
|
||||
}
|
||||
|
||||
|
@ -9,13 +9,13 @@ type UUID struct {
|
||||
payload uuid.UUID
|
||||
}
|
||||
|
||||
func NewUUID() UUID {
|
||||
func MakeUUID() UUID {
|
||||
id, _ := uuid.NewRandom()
|
||||
return UUID { payload: id }
|
||||
}
|
||||
|
||||
func (self UUID) Value() (sqldriver.Value, error) {
|
||||
return self.payload.MarshalBinary()
|
||||
return self.payload[:], nil
|
||||
}
|
||||
|
||||
func (self *UUID) Scan(value any) error {
|
||||
|
Reference in New Issue
Block a user