package events

import (
	"testing"
	"time"
)

func TestNewTimeWindowFromNow(t *testing.T) {
	duration := time.Second
	window := NewTimeWindowFromNow(duration)

	if window.Begin.Add(duration) != window.End {
		t.Errorf("Bad window end. Expect %v got %v", window.Begin.Add(duration), window.End)
	}
}

func TestTimeWindowHash(t *testing.T) {
	layout := "2006-01-02T15:04:05.000Z"
	str1 := "2014-11-12T11:45:26.371Z"
	str2 := "2014-12-12T11:45:26.371Z"

	t1, err := time.Parse(layout, str1)
	if err != nil {
		t.Errorf("%v", err)
		return
	}

	t2, err := time.Parse(layout, str2)
	if err != nil {
		t.Errorf("%v", err)
		return
	}

	window := TimeWindow{
		Begin: t1,
		End:   t2,
	}

	hash := window.Hash()
	goodHash := uint32(1686523187)

	if hash != goodHash {
		t.Errorf("Bad timewindow hash. Expect %v, got %v", goodHash, hash)
	}
}
