v0.0.424 timeext.SubtractYears
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m29s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m29s
This commit is contained in:
parent
6c4af4006b
commit
9491b72b8d
@ -1,5 +1,5 @@
|
|||||||
package goext
|
package goext
|
||||||
|
|
||||||
const GoextVersion = "0.0.423"
|
const GoextVersion = "0.0.424"
|
||||||
|
|
||||||
const GoextVersionTimestamp = "2024-03-24T15:25:52+0100"
|
const GoextVersionTimestamp = "2024-03-30T03:01:55+0100"
|
||||||
|
@ -146,3 +146,37 @@ func UnixFloatSeconds(v float64) time.Time {
|
|||||||
func FloorTime(t time.Time) time.Time {
|
func FloorTime(t time.Time) time.Time {
|
||||||
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
|
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SubtractYears(t time.Time, yearCount float64, tz *time.Location) time.Time {
|
||||||
|
t = t.In(tz)
|
||||||
|
|
||||||
|
if yearCount < 0 {
|
||||||
|
return AddYears(t, -yearCount, tz)
|
||||||
|
}
|
||||||
|
|
||||||
|
intCount, floatCount := math.Modf(yearCount)
|
||||||
|
|
||||||
|
t.AddDate(-int(intCount), 0, 0)
|
||||||
|
|
||||||
|
t0 := TimeToYearStart(t, tz)
|
||||||
|
t1 := TimeToYearEnd(t, tz)
|
||||||
|
|
||||||
|
return t.Add(time.Duration(float64(t1.Sub(t0)) * floatCount * -1))
|
||||||
|
}
|
||||||
|
|
||||||
|
func AddYears(t time.Time, yearCount float64, tz *time.Location) time.Time {
|
||||||
|
t = t.In(tz)
|
||||||
|
|
||||||
|
if yearCount < 0 {
|
||||||
|
return SubtractYears(t, -yearCount, tz)
|
||||||
|
}
|
||||||
|
|
||||||
|
intCount, floatCount := math.Modf(yearCount)
|
||||||
|
|
||||||
|
t.AddDate(int(intCount), 0, 0)
|
||||||
|
|
||||||
|
t0 := TimeToYearStart(t, tz)
|
||||||
|
t1 := TimeToYearEnd(t, tz)
|
||||||
|
|
||||||
|
return t.Add(time.Duration(float64(t1.Sub(t0)) * floatCount))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user