Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
36b71dfaf3
|
|||
9491b72b8d
|
|||
6c4af4006b
|
|||
8bf3a337cf
|
@@ -16,10 +16,6 @@ func (m JsonOpt[T]) MarshalJSON() ([]byte, error) {
|
||||
return []byte("null"), nil // actually this would be undefined - but undefined is not valid JSON
|
||||
}
|
||||
|
||||
if m.value == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
|
||||
return json.Marshal(m.value)
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.421"
|
||||
const GoextVersion = "0.0.425"
|
||||
|
||||
const GoextVersionTimestamp = "2024-03-23T20:28:51+0100"
|
||||
const GoextVersionTimestamp = "2024-03-30T14:24:53+0100"
|
||||
|
@@ -453,6 +453,15 @@ func ArrConcat[T any](arr ...[]T) []T {
|
||||
return r
|
||||
}
|
||||
|
||||
// ArrAppend works similar to append(x, y, z) - but doe snot touch the old array and creates a new one
|
||||
func ArrAppend[T any](arr []T, add ...T) []T {
|
||||
r := ArrCopy(arr)
|
||||
for _, v := range add {
|
||||
r = append(r, v)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// ArrCopy does a shallow copy of the 'in' array
|
||||
func ArrCopy[T any](in []T) []T {
|
||||
out := make([]T, len(in))
|
||||
|
@@ -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