func TestRetryFuncError(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	err := timex.Retry(func() (bool, error) {
		return false, errors.New("ouch")
	}, timex.ShortAttempt())
	assert.ErrorMatch(err, "ouch")
}
TestRetryFuncError tests an error inside the retried func.
package timex_test
import (
	"errors"
	"testing"
	"time"
	"github.com/tideland/golib/audit"
	"github.com/tideland/golib/timex"
)
func TestTimeContainments(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	ts := time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)
	years := []int{2008, 2009, 2010}
	months := []time.Month{10, 11, 12}
	days := []int{10, 11, 12, 13, 14}
	hours := []int{20, 21, 22, 23}
	minutes := []int{0, 5, 10, 15, 20, 25}
	seconds := []int{0, 15, 30, 45}
	weekdays := []time.Weekday{time.Monday, time.Tuesday, time.Wednesday}
	assert.True(timex.YearInList(ts, years), "Go time in year list.")
	assert.True(timex.YearInRange(ts, 2005, 2015), "Go time in year range.")
	assert.True(timex.MonthInList(ts, months), "Go time in month list.")
	assert.True(timex.MonthInRange(ts, 7, 12), "Go time in month range.")
	assert.True(timex.DayInList(ts, days), "Go time in day list.")
	assert.True(timex.DayInRange(ts, 5, 15), "Go time in day range .")
	assert.True(timex.HourInList(ts, hours), "Go time in hour list.")
	assert.True(timex.HourInRange(ts, 20, 31), "Go time in hour range .")
	assert.True(timex.MinuteInList(ts, minutes), "Go time in minute list.")
	assert.True(timex.MinuteInRange(ts, 0, 5), "Go time in minute range .")
	assert.True(timex.SecondInList(ts, seconds), "Go time in second list.")
	assert.True(timex.SecondInRange(ts, 0, 5), "Go time in second range .")
	assert.True(timex.WeekdayInList(ts, weekdays), "Go time in weekday list.")
	assert.True(timex.WeekdayInRange(ts, time.Monday, time.Friday), "Go time in weekday range .")
}
func TestBeginOf(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	ts := time.Date(2015, time.August, 2, 15, 10, 45, 12345, time.UTC)
	assert.Equal(timex.BeginOf(ts, timex.Second), time.Date(2015, time.August, 2, 15, 10, 45, 0, time.UTC))
	assert.Equal(timex.BeginOf(ts, timex.Minute), time.Date(2015, time.August, 2, 15, 10, 0, 0, time.UTC))
	assert.Equal(timex.BeginOf(ts, timex.Hour), time.Date(2015, time.August, 2, 15, 0, 0, 0, time.UTC))
	assert.Equal(timex.BeginOf(ts, timex.Day), time.Date(2015, time.August, 2, 0, 0, 0, 0, time.UTC))
	assert.Equal(timex.BeginOf(ts, timex.Month), time.Date(2015, time.August, 1, 0, 0, 0, 0, time.UTC))
	assert.Equal(timex.BeginOf(ts, timex.Year), time.Date(2015, time.January, 1, 0, 0, 0, 0, time.UTC))
}
func TestEndOf(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	ts := time.Date(2012, time.February, 2, 15, 10, 45, 12345, time.UTC)
	assert.Equal(timex.EndOf(ts, timex.Second), time.Date(2012, time.February, 2, 15, 10, 45, 999999999, time.UTC))
	assert.Equal(timex.EndOf(ts, timex.Minute), time.Date(2012, time.February, 2, 15, 10, 59, 999999999, time.UTC))
	assert.Equal(timex.EndOf(ts, timex.Hour), time.Date(2012, time.February, 2, 15, 59, 59, 999999999, time.UTC))
	assert.Equal(timex.EndOf(ts, timex.Day), time.Date(2012, time.February, 2, 23, 59, 59, 999999999, time.UTC))
	assert.Equal(timex.EndOf(ts, timex.Month), time.Date(2012, time.February, 29, 23, 59, 59, 999999999, time.UTC))
	assert.Equal(timex.EndOf(ts, timex.Year), time.Date(2012, time.December, 31, 23, 59, 59, 999999999, time.UTC))
}
func TestCrontabKeep(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	c := timex.NewCrontab(50 * time.Millisecond)
	j := &cronjob{[]time.Time{}, false, false}
	c.Add("keep", j)
	time.Sleep(time.Second)
	c.Remove("keep")
	c.Stop()
	for i := range j.times {
		if i > 0 {
			d := j.times[i].Sub(j.times[i-1])
			assert.True(d.Seconds() >= 0.05)
		}
	}
}
func TestCrontabRemove(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	c := timex.NewCrontab(10 * time.Millisecond)
	j := &cronjob{[]time.Time{}, false, false}
	c.Add("remove", j)
	time.Sleep(500 * time.Millisecond)
	c.Remove("remove")
	c.Stop()
	assert.Length(j.times, 10, "job counter increased max ten times")
}
func TestCrontabError(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	c := timex.NewCrontab(10 * time.Millisecond)
	j := &cronjob{[]time.Time{}, false, true}
	c.Add("remove", j)
	time.Sleep(500 * time.Millisecond)
	c.Remove("remove")
	c.Stop()
	assert.Length(j.times, 5, "job counter increased max five times")
}
func TestRetrySuccess(t *testing.T) {
	assert := audit.NewTestingAssertion(t, true)
	count := 0
	err := timex.Retry(func() (bool, error) {
		count++
		return count == 5, nil
	}, timex.ShortAttempt())
	assert.Nil(err)
	assert.Equal(count, 5)
}