Skip to content

Commit

Permalink
[enhance:lindb#1021]: fix GetMonthTimestamp func
Browse files Browse the repository at this point in the history
  • Loading branch information
joyant committed May 17, 2024
1 parent 9e19d06 commit 2acf953
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/timeutil/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ func CalIntervalRatio(queryInterval, storageInterval int64) int {
func GetMonthTimestamp(familyTime int64) int64 {
tm := time.Unix(familyTime/1000, 0)
ts := time.Date(tm.Year(), tm.Month(), 1, 0, 0, 0, 0, time.Local)
return ts.Unix() * 1000
return ts.UnixNano() / 1000000
}
10 changes: 6 additions & 4 deletions pkg/timeutil/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
package timeutil

import (
"testing"

"github.com/lindb/common/pkg/timeutil"

"github.com/stretchr/testify/assert"

"testing"
)

const date = "20191212 10:11:10"
Expand Down Expand Up @@ -49,6 +50,7 @@ func TestTruncate(t *testing.T) {
}

func TestGetMonthTimestamp(t *testing.T) {
got := GetMonthTimestamp(1715787380378)
assert.Equal(t, int64(1714492800000), got)
now, _ := timeutil.ParseTimestamp("20190711 12:30:30", "20060102 15:04:05")
t1, _ := timeutil.ParseTimestamp("20190701 00:00:00", "20060102 15:04:05")
assert.Equal(t, t1, GetMonthTimestamp(now))
}

0 comments on commit 2acf953

Please sign in to comment.