v0.0.79
This commit is contained in:
59
rfctime/seconds.go
Normal file
59
rfctime/seconds.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package rfctime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/timeext"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SecondsF64 time.Duration
|
||||
|
||||
func (d SecondsF64) Duration() time.Duration {
|
||||
return time.Duration(d)
|
||||
}
|
||||
|
||||
func (d SecondsF64) String() string {
|
||||
return d.Duration().String()
|
||||
}
|
||||
|
||||
func (d SecondsF64) Nanoseconds() int64 {
|
||||
return d.Duration().Nanoseconds()
|
||||
}
|
||||
|
||||
func (d SecondsF64) Microseconds() int64 {
|
||||
return d.Duration().Microseconds()
|
||||
}
|
||||
|
||||
func (d SecondsF64) Milliseconds() int64 {
|
||||
return d.Duration().Milliseconds()
|
||||
}
|
||||
|
||||
func (d SecondsF64) Seconds() float64 {
|
||||
return d.Duration().Seconds()
|
||||
}
|
||||
|
||||
func (d SecondsF64) Minutes() float64 {
|
||||
return d.Duration().Minutes()
|
||||
}
|
||||
|
||||
func (d SecondsF64) Hours() float64 {
|
||||
return d.Duration().Hours()
|
||||
}
|
||||
|
||||
func (d *SecondsF64) UnmarshalJSON(data []byte) error {
|
||||
var secs float64 = 0
|
||||
if err := json.Unmarshal(data, &secs); err != nil {
|
||||
return err
|
||||
}
|
||||
*d = SecondsF64(timeext.FromSeconds(secs))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d SecondsF64) MarshalJSON() ([]byte, error) {
|
||||
secs := d.Seconds()
|
||||
return json.Marshal(secs)
|
||||
}
|
||||
|
||||
func NewSecondsF64(t time.Duration) SecondsF64 {
|
||||
return SecondsF64(t)
|
||||
}
|
Reference in New Issue
Block a user