Goのtime.Time{}はUnixTimeの0ではなくZeroValue
https://1.bp.blogspot.com/-6C2-OWVKtPo/UX-M_olXyqI/AAAAAAAAQ04/h3kZmUDxesY/s1600/monogatari_alice.png
Goのtimeパッケージの仕様でゼロ値は特別扱いされている そのため UnixTime:0 で初期化した time.Time 構造体は IsZero の判定が false になる
UnixTime:0 かを判定するには time.UnixNano == 0 で判定すると良い
また、ゼロ値が特例的に扱われているため、time.Time のポインタ型は通常登場しないことになっている
Programs using times should typically store and pass them as values, not pointers. That is, time variables and struct fields should be of type time.Time, not *time.Time.
(時間を使用するプログラムは、通常、ポインターではなく値として保存して渡す必要があります。つまり、時間変数と構造体フィールドは、*time.Time ではなく、time.Time 型である必要があります。)
code:go
package main
import (
"fmt"
"time"
)
func main() {
// ゼロ値として初期化された time.Time
zeroTime := time.Time{}
fmt.Println(zeroTime.Unix()) // => -62135596800
fmt.Println(zeroTime.IsZero()) // => true
fmt.Println(zeroTime.UnixNano() == 0) // => false
// UnixTime:0 として初期化された time.Time
unixZeroTime := time.Unix(0, 0)
fmt.Println(unixZeroTime.Unix()) // => 0
fmt.Println(unixZeroTime.IsZero()) // => false
fmt.Println(unixZeroTime.UnixNano() == 0) // => true
}
関連