Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
9491b72b8d
|
|||
6c4af4006b
|
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.422"
|
||||
const GoextVersion = "0.0.424"
|
||||
|
||||
const GoextVersionTimestamp = "2024-03-23T20:29:46+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 {
|
||||
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))
|
||||
}
|
||||
|
@@ -171,7 +171,7 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CursorToken
|
||||
bson.M{*fieldSecondary: bson.M{"$gt": valueSecondary}},
|
||||
}})
|
||||
|
||||
sort = append(sort, bson.E{Key: fieldPrimary, Value: +1})
|
||||
sort = append(sort, bson.E{Key: *fieldSecondary, Value: +1})
|
||||
|
||||
} else if *sortSecondary == ct.SortDESC {
|
||||
|
||||
@@ -181,7 +181,7 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CursorToken
|
||||
bson.M{*fieldSecondary: bson.M{"$lt": valueSecondary}},
|
||||
}})
|
||||
|
||||
sort = append(sort, bson.E{Key: fieldPrimary, Value: -1})
|
||||
sort = append(sort, bson.E{Key: *fieldSecondary, Value: -1})
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user