forked from ebhomengo/niki
33 lines
656 B
Go
33 lines
656 B
Go
package analytic
|
|
|
|
import "time"
|
|
|
|
func normalizeLimitOffset(limit, offset int) (int, int) {
|
|
if limit <= 0 {
|
|
limit = 50
|
|
}
|
|
if limit > 100 {
|
|
limit = 100
|
|
}
|
|
if offset < 0 {
|
|
offset = 0
|
|
}
|
|
return limit, offset
|
|
}
|
|
|
|
// convert age range -> DOB range
|
|
func ageRangeToDOB(minAge, maxAge *int, now time.Time) (dobFrom, dobTo *time.Time) {
|
|
// maxAge => DOB >= now-(maxAge+1y)+1day
|
|
// eg: now is : 3/31/2026; maxAge=30 => (now - 31)= 3/31/1994 => +=1
|
|
if maxAge != nil {
|
|
t := now.AddDate(-*maxAge-1, 0, 0).Add(24 * time.Hour)
|
|
dobFrom = &t
|
|
}
|
|
// minAge => DOB <= now-minAge
|
|
if minAge != nil {
|
|
t := now.AddDate(-*minAge, 0, 0)
|
|
dobTo = &t
|
|
}
|
|
return
|
|
}
|