mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: make intervals robust to daylight saving time shift
This commit is contained in:
parent
c8ea1a503f
commit
9586dbf781
File diff suppressed because it is too large
Load Diff
@ -86,7 +86,7 @@ func (h *StatsHandler) Get(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
minStart := rangeTo.Add(-24 * time.Hour * time.Duration(requestedUser.ShareDataMaxDays))
|
minStart := rangeTo.AddDate(0, 0, -requestedUser.ShareDataMaxDays)
|
||||||
if (authorizedUser == nil || requestedUser.ID != authorizedUser.ID) &&
|
if (authorizedUser == nil || requestedUser.ID != authorizedUser.ID) &&
|
||||||
rangeFrom.Before(minStart) && requestedUser.ShareDataMaxDays >= 0 {
|
rangeFrom.Before(minStart) && requestedUser.ShareDataMaxDays >= 0 {
|
||||||
w.WriteHeader(http.StatusForbidden)
|
w.WriteHeader(http.StatusForbidden)
|
||||||
|
@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/muety/wakapi/utils"
|
"github.com/muety/wakapi/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -43,7 +42,7 @@ func GetBadgeParams(r *http.Request, requestedUser *models.User) (*models.KeyedI
|
|||||||
Key: intervalKey,
|
Key: intervalKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
minStart := rangeTo.Add(-24 * time.Hour * time.Duration(requestedUser.ShareDataMaxDays))
|
minStart := rangeTo.AddDate(0, 0, -requestedUser.ShareDataMaxDays)
|
||||||
// negative value means no limit
|
// negative value means no limit
|
||||||
if rangeFrom.Before(minStart) && requestedUser.ShareDataMaxDays >= 0 {
|
if rangeFrom.Before(minStart) && requestedUser.ShareDataMaxDays >= 0 {
|
||||||
return nil, nil, errors.New("requested time range too broad")
|
return nil, nil, errors.New("requested time range too broad")
|
||||||
|
Loading…
Reference in New Issue
Block a user