Skip to content
Snippets Groups Projects
Select Git revision
  • 076807d78d7e26425229805083733cbb2f9b7693
  • main default protected
  • v1.298.0
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
  • v1.283.0
  • v1.282.0
  • v1.281.0
  • v1.280.0
  • v1.279.0
22 results

periods_test.go

Blame
  • periods_test.go 1.62 KiB
    package logs_test
    
    import (
    	"testing"
    	"time"
    
    	"gitlab.com/uafrica/go-utils/logger"
    	"gitlab.com/uafrica/go-utils/logs"
    )
    
    func TestPeriods(t *testing.T) {
    	logger.SetGlobalFormat(logger.NewConsole())
    	logger.SetGlobalLevel(logger.LevelDebug)
    	t0 := time.Date(2021, 01, 01, 0, 0, 0, 0, time.Now().Location())
    	ps := logs.NewPeriods(t0, t0.Add(time.Hour))
    	t.Log(ps)
    	//ps: 0..60
    
    	//split[0]
    	ps1 := ps.Without(logs.Period{Start: t0.Add(time.Minute * 5), End: t0.Add(time.Minute * 10)})
    	t.Log(ps1)
    	//-(5..10) -> ps1: 0..5, 10..60
    
    	//split[1]
    	ps2 := ps1.Without(logs.Period{Start: t0.Add(time.Minute * 15), End: t0.Add(time.Minute * 20)})
    	t.Log(ps2)
    	//-(15..20) -> ps1: 0..5, 10..15, 20..60
    
    	//trim head[2]
    	ps3 := ps2.Without(logs.Period{Start: t0.Add(time.Minute * 18), End: t0.Add(time.Minute * 21)})
    	t.Log(ps3)
    	//-(18..21) -> ps1: 0..5, 10..15, 21..60
    
    	//trim tail[1]
    	ps4 := ps3.Without(logs.Period{Start: t0.Add(time.Minute * 14), End: t0.Add(time.Minute * 19)})
    	t.Log(ps4)
    	//-(14..19) -> ps1: 0..5, 10..14, 21..60
    
    	//tail, delete, head
    	ps5 := ps4.Without(logs.Period{Start: t0.Add(time.Minute * 4), End: t0.Add(time.Minute * 22)})
    	t.Log(ps5)
    	//-(4..22) -> ps1: 0..4, 22..60
    
    	//over start
    	ps6 := ps5.Without(logs.Period{Start: t0.Add(-time.Minute * 1), End: t0.Add(time.Minute * 2)})
    	t.Log(ps6)
    	//-(-1..2) -> ps1: 2..4, 22..60
    
    	//over end
    	ps7 := ps6.Without(logs.Period{Start: t0.Add(time.Minute * 50), End: t0.Add(time.Minute * 120)})
    	t.Log(ps7)
    	//-(50..120) -> ps1: 2..4, 22..50
    
    	//all
    	ps8 := ps7.Without(logs.Period{Start: t0.Add(time.Minute * 0), End: t0.Add(time.Minute * 120)})
    	t.Log(ps8)
    	//-(0..120) -> ps1: nil
    
    }