diff --git a/waku/v2/utils/time.go b/waku/v2/utils/time.go index 2d7b0aba..90227774 100644 --- a/waku/v2/utils/time.go +++ b/waku/v2/utils/time.go @@ -2,6 +2,10 @@ package utils import "time" -func GetUnixEpoch() float64 { - return float64(time.Now().UnixNano()) / float64(time.Second) +func GetUnixEpochFrom(now func() time.Time) float64 { + return float64(now().UnixNano()) / float64(time.Second) +} + +func GetUnixEpoch() float64 { + return GetUnixEpochFrom(time.Now) } diff --git a/waku/v2/utils/time_test.go b/waku/v2/utils/time_test.go new file mode 100644 index 00000000..a0aa68c4 --- /dev/null +++ b/waku/v2/utils/time_test.go @@ -0,0 +1,18 @@ +package utils + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" +) + +func TestGetUnixEpochFrom(t *testing.T) { + loc := time.UTC + timeFn := func() time.Time { + return time.Date(2019, 1, 1, 0, 0, 0, 0, loc) + } + timestamp := GetUnixEpochFrom(timeFn) + + require.Equal(t, float64(1546300800), timestamp) +}