github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/attime/attime_test.go (about)

     1  package attime
     2  
     3  import (
     4  	"time"
     5  
     6  	. "github.com/onsi/ginkgo/v2"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("attime", func() {
    11  	Describe("Parse", func() {
    12  		Context("simple cases", func() {
    13  			It("works correctly", func() {
    14  				Expect(Parse("now")).To(BeTemporally("~", time.Now()))
    15  				Expect(Parse("now-1s")).To(BeTemporally("~", time.Now().Add(-1*time.Second)))
    16  				Expect(Parse("now+1s")).To(BeTemporally("~", time.Now().Add(1*time.Second)))
    17  				Expect(Parse("now-1min")).To(BeTemporally("~", time.Now().Add(-1*time.Minute)))
    18  				Expect(Parse("now-1h")).To(BeTemporally("~", time.Now().Add(-1*time.Hour)))
    19  				Expect(Parse("now-1d")).To(BeTemporally("~", time.Now().Add(-1*time.Hour*24)))
    20  				Expect(Parse("now-1w")).To(BeTemporally("~", time.Now().Add(-1*time.Hour*24*7)))
    21  				Expect(Parse("now-1mon")).To(BeTemporally("~", time.Now().Add(-1*time.Hour*24*30)))
    22  				Expect(Parse("now-1M")).To(BeTemporally("~", time.Now().Add(-1*time.Hour*24*30)))
    23  				Expect(Parse("now-1y")).To(BeTemporally("~", time.Now().Add(-1*time.Hour*24*365)))
    24  				Expect(Parse("now-1")).To(BeTemporally("~", time.Now()))
    25  				Expect(Parse("20200101")).To(BeTemporally("~", time.Unix(1577836800, 0)))
    26  				Expect(Parse("1577836800")).To(BeTemporally("~", time.Unix(1577836800, 0)))
    27  				Expect(Parse("1577836800001")).To(BeTemporally("~", time.Unix(1577836800, 1000000)))
    28  				Expect(Parse("1577836800000001")).To(BeTemporally("~", time.Unix(1577836800, 1000)))
    29  				Expect(Parse("1577836800000000001")).To(BeTemporally("~", time.Unix(1577836800, 1)))
    30  			})
    31  		})
    32  	})
    33  })