Exemplo n.º 1
0
func TestStrToTime(t *testing.T) {
	// zoneName, err := time.LoadLocation("CST")
	// if err != nil {
	//     t.Error(err)
	// }

	var testCases = []test{
		{
			time.Date(2012, 11, 22, 21, 28, 10, 0, time.Local),
			"",
			"2012-11-22 21:28:10 +0800 +0800",
		},
		{
			time.Date(2012, 11, 22, 0, 0, 0, 0, time.Local),
			"",
			"2012-11-22 +0800 +0800",
		},
		{
			time.Date(2012, 11, 22, 21, 28, 10, 0, time.FixedZone("CST", 28800)),
			"",
			"2012-11-22 21:28:10 +0800 CST",
		},
	}
	for _, testCase := range testCases {
		time := StrToTime(testCase.strTime)
		// if time != testCase.time {
		if !time.Equal(testCase.time) {
			t.Errorf("(expected) %v != %v (actual)", time, testCase.time)
		}
	}
}
Exemplo n.º 2
0
func TestDate(t *testing.T) {
	for _, tt := range dateTests {
		time := Date(tt.year, Month(tt.month), tt.day, tt.hour, tt.min, tt.sec, tt.nsec, tt.z)
		want := Unix(tt.unix, 0)
		if !time.Equal(want) {
			t.Errorf("Date(%d, %d, %d, %d, %d, %d, %d, %s) = %v, want %v",
				tt.year, tt.month, tt.day, tt.hour, tt.min, tt.sec, tt.nsec, tt.z,
				time, want)
		}
	}
}
Exemplo n.º 3
0
func TestAddDate(t *testing.T) {
	t0 := Date(2011, 11, 18, 7, 56, 35, 0, UTC)
	t1 := Date(2016, 3, 19, 7, 56, 35, 0, UTC)
	for _, at := range addDateTests {
		time := t0.AddDate(at.years, at.months, at.days)
		if !time.Equal(t1) {
			t.Errorf("AddDate(%d, %d, %d) = %v, want %v",
				at.years, at.months, at.days,
				time, t1)
		}
	}
}