本文整理匯總了Golang中Time.Equal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Equal函數的具體用法?Golang Equal怎麽用?Golang Equal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Equal函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestStrToTime
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)
}
}
}
示例2: TestDate
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)
}
}
}
示例3: TestAddDate
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)
}
}
}