This commit is contained in:
Mike Schwörer 2022-11-30 22:09:54 +01:00
parent 9d9a6f1c6e
commit deab986caf
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF

View File

@ -2,59 +2,36 @@ package timeext
import (
"fmt"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"time"
)
func FromSeconds(v int) time.Duration {
return time.Duration(int64(v) * int64(time.Second))
func FromNanoseconds[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(time.Nanosecond)))
}
func FromSecondsInt32(v int32) time.Duration {
return time.Duration(int64(v) * int64(time.Second))
func FromMicroseconds[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(time.Microsecond)))
}
func FromSecondsInt64(v int64) time.Duration {
return time.Duration(v * int64(time.Second))
func FromMilliseconds[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(time.Millisecond)))
}
func FromSecondsFloat32(v float32) time.Duration {
return time.Duration(int64(v * float32(time.Second)))
func FromSeconds[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(time.Second)))
}
func FromSecondsFloat64(v float64) time.Duration {
return time.Duration(int64(v * float64(time.Second)))
func FromMinutes[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(time.Minute)))
}
func FromSecondsFloat(v float64) time.Duration {
return time.Duration(int64(v * float64(time.Second)))
func FromHours[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(time.Hour)))
}
func FromMinutes(v int) time.Duration {
return time.Duration(int64(v) * int64(time.Minute))
}
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 FromDays[T langext.NumberConstraint](v T) time.Duration {
return time.Duration(int64(float64(v) * float64(24) * float64(time.Hour)))
}
func FormatNaturalDurationEnglish(iv time.Duration) string {