Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
496c4e4f59
|
|||
deab986caf
|
27
syncext/atomic.go
Normal file
27
syncext/atomic.go
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package dataext
|
||||||
|
|
||||||
|
import "sync/atomic"
|
||||||
|
|
||||||
|
type AtomicBool struct {
|
||||||
|
v int32
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAtomicBool(value bool) *AtomicBool {
|
||||||
|
if value {
|
||||||
|
return &AtomicBool{v: 0}
|
||||||
|
} else {
|
||||||
|
return &AtomicBool{v: 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AtomicBool) Get() bool {
|
||||||
|
return atomic.LoadInt32(&a.v) == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AtomicBool) Set(value bool) {
|
||||||
|
if value {
|
||||||
|
atomic.StoreInt32(&a.v, 1)
|
||||||
|
} else {
|
||||||
|
atomic.StoreInt32(&a.v, 0)
|
||||||
|
}
|
||||||
|
}
|
@@ -2,59 +2,36 @@ package timeext
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FromSeconds(v int) time.Duration {
|
func FromNanoseconds[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(int64(v) * int64(time.Second))
|
return time.Duration(int64(float64(v) * float64(time.Nanosecond)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromSecondsInt32(v int32) time.Duration {
|
func FromMicroseconds[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(int64(v) * int64(time.Second))
|
return time.Duration(int64(float64(v) * float64(time.Microsecond)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromSecondsInt64(v int64) time.Duration {
|
func FromMilliseconds[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(v * int64(time.Second))
|
return time.Duration(int64(float64(v) * float64(time.Millisecond)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromSecondsFloat32(v float32) time.Duration {
|
func FromSeconds[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(int64(v * float32(time.Second)))
|
return time.Duration(int64(float64(v) * float64(time.Second)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromSecondsFloat64(v float64) time.Duration {
|
func FromMinutes[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(int64(v * float64(time.Second)))
|
return time.Duration(int64(float64(v) * float64(time.Minute)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromSecondsFloat(v float64) time.Duration {
|
func FromHours[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(int64(v * float64(time.Second)))
|
return time.Duration(int64(float64(v) * float64(time.Hour)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func FromMinutes(v int) time.Duration {
|
func FromDays[T langext.NumberConstraint](v T) time.Duration {
|
||||||
return time.Duration(int64(v) * int64(time.Minute))
|
return time.Duration(int64(float64(v) * float64(24) * float64(time.Hour)))
|
||||||
}
|
|
||||||
|
|
||||||
func FromMinutesFloat(v float64) time.Duration {
|
|
||||||
return time.Duration(int64(v * float64(time.Minute)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FromMinutesFloat64(v float64) time.Duration {
|
|
||||||
return time.Duration(int64(v * float64(time.Minute)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FromHoursFloat64(v float64) time.Duration {
|
|
||||||
return time.Duration(int64(v * float64(time.Hour)))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FromDays(v int) time.Duration {
|
|
||||||
return time.Duration(int64(v) * int64(24) * int64(time.Hour))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FromMilliseconds(v int) time.Duration {
|
|
||||||
return time.Duration(int64(v) * int64(time.Millisecond))
|
|
||||||
}
|
|
||||||
|
|
||||||
func FromMillisecondsFloat(v float64) time.Duration {
|
|
||||||
return time.Duration(int64(v * float64(time.Millisecond)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatNaturalDurationEnglish(iv time.Duration) string {
|
func FormatNaturalDurationEnglish(iv time.Duration) string {
|
||||||
|
Reference in New Issue
Block a user