mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-01 19:47:37 +03:00
Uses Unix milliseconds support from standard Go lib
This commit is contained in:
parent
ec68d69d56
commit
30ae468dc1
6 changed files with 10 additions and 43 deletions
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/navidrome/navidrome/server/public"
|
||||
"github.com/navidrome/navidrome/server/subsonic/filter"
|
||||
"github.com/navidrome/navidrome/server/subsonic/responses"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
"github.com/navidrome/navidrome/utils/req"
|
||||
)
|
||||
|
||||
|
@ -45,7 +44,7 @@ func (api *Router) getArtistIndex(r *http.Request, mediaFolderId int, ifModified
|
|||
|
||||
var indexes model.ArtistIndexes
|
||||
ms, _ := strconv.ParseInt(l, 10, 64)
|
||||
lastModified := utils.ToTime(ms)
|
||||
lastModified := time.UnixMilli(ms)
|
||||
if lastModified.After(ifModifiedSince) {
|
||||
indexes, err = api.ds.Artist(ctx).GetIndex()
|
||||
if err != nil {
|
||||
|
@ -56,7 +55,7 @@ func (api *Router) getArtistIndex(r *http.Request, mediaFolderId int, ifModified
|
|||
|
||||
res := &responses.Indexes{
|
||||
IgnoredArticles: conf.Server.IgnoredArticles,
|
||||
LastModified: utils.ToMillis(lastModified),
|
||||
LastModified: lastModified.UnixMilli(),
|
||||
}
|
||||
|
||||
res.Index = make([]responses.Index, len(indexes))
|
||||
|
|
|
@ -6,13 +6,11 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/model/request"
|
||||
|
||||
"github.com/navidrome/navidrome/core/scrobbler"
|
||||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/request"
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
"github.com/navidrome/navidrome/tests"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
@ -49,9 +47,9 @@ var _ = Describe("MediaAnnotationController", func() {
|
|||
|
||||
It("submit all scrobbles with respective times", func() {
|
||||
time1 := time.Now().Add(-20 * time.Minute)
|
||||
t1 := utils.ToMillis(time1)
|
||||
t1 := time1.UnixMilli()
|
||||
time2 := time.Now().Add(-10 * time.Minute)
|
||||
t2 := utils.ToMillis(time2)
|
||||
t2 := time2.UnixMilli()
|
||||
r := newGetRequest("id=12", "id=34", fmt.Sprintf("time=%d", t1), fmt.Sprintf("time=%d", t2))
|
||||
|
||||
_, err := router.Scrobble(r)
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
)
|
||||
|
||||
type Values struct {
|
||||
|
@ -61,7 +60,7 @@ func (r *Values) TimeOr(param string, def time.Time) time.Time {
|
|||
if err != nil {
|
||||
return def
|
||||
}
|
||||
t := utils.ToTime(value)
|
||||
t := time.UnixMilli(value)
|
||||
if t.Before(time.Date(1970, time.January, 2, 0, 0, 0, 0, time.UTC)) {
|
||||
return def
|
||||
}
|
||||
|
@ -81,7 +80,7 @@ func (r *Values) Times(param string) ([]time.Time, error) {
|
|||
times[i] = time.Now()
|
||||
continue
|
||||
}
|
||||
times[i] = utils.ToTime(ti)
|
||||
times[i] = time.UnixMilli(ti)
|
||||
}
|
||||
return times, nil
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/navidrome/navidrome/utils"
|
||||
"github.com/navidrome/navidrome/utils/req"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -69,7 +68,7 @@ var _ = Describe("Request Helpers", func() {
|
|||
|
||||
Describe("ParamTime", func() {
|
||||
d := time.Date(2002, 8, 9, 12, 11, 13, 1000000, time.Local)
|
||||
t := utils.ToMillis(d)
|
||||
t := d.UnixMilli()
|
||||
now := time.Now()
|
||||
BeforeEach(func() {
|
||||
r = req.Params(httptest.NewRequest("GET", fmt.Sprintf("/ping?t=%d&inv=abc", t), nil))
|
||||
|
@ -91,8 +90,8 @@ var _ = Describe("Request Helpers", func() {
|
|||
Describe("ParamTimes", func() {
|
||||
d1 := time.Date(2002, 8, 9, 12, 11, 13, 1000000, time.Local)
|
||||
d2 := time.Date(2002, 8, 9, 12, 13, 56, 0000000, time.Local)
|
||||
t1 := utils.ToMillis(d1)
|
||||
t2 := utils.ToMillis(d2)
|
||||
t1 := d1.UnixMilli()
|
||||
t2 := d2.UnixMilli()
|
||||
BeforeEach(func() {
|
||||
r = req.Params(httptest.NewRequest("GET", fmt.Sprintf("/ping?t=%d&t=%d", t1, t2), nil))
|
||||
})
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package utils
|
||||
|
||||
import "time"
|
||||
|
||||
func ToTime(millis int64) time.Time {
|
||||
t := time.Unix(0, millis*int64(time.Millisecond))
|
||||
return t.Local()
|
||||
}
|
||||
|
||||
func ToMillis(t time.Time) int64 {
|
||||
return t.UnixNano() / int64(time.Millisecond)
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Time Conversion", func() {
|
||||
It("converts from Date to Millis and back to Date", func() {
|
||||
date := time.Date(2002, 8, 9, 12, 11, 13, 1000000, time.Local)
|
||||
milli := ToMillis(date)
|
||||
Expect(ToTime(milli)).To(Equal(date))
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue