Last active
August 29, 2015 14:18
-
-
Save patdowney/b64a4fee790ac66dd1a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
"time" | |
) | |
func TestDefaultTimeToUnixNanoAndBackAgain(t *testing.T) { | |
var defaultTime time.Time // 0001-01-01 00:00:00 +0000 UTC | |
encodedDefaultTime := defaultTime.UnixNano() //gives -6795364578871345152 | |
decodedDefaultTime := time.Unix(0, encodedDefaultTime) | |
if defaultTime != decodedDefaultTime { | |
t.Errorf("expected: %v, got %v", defaultTime, decodedDefaultTime) | |
} | |
} | |
func TestDefaultTimeToUnixAndBackAgain(t *testing.T) { | |
var defaultTime time.Time // 0001-01-01 00:00:00 +0000 UTC | |
encodedDefaultTime := defaultTime.Unix() //gives -62135596800 | |
decodedDefaultTime := time.Unix(encodedDefaultTime, 0) | |
if defaultTime != decodedDefaultTime { | |
t.Errorf("expected: %v, got %v", defaultTime, decodedDefaultTime) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func TestDefaultTimeToUnixNanoAndBackAgain() { | |
var defaultTime time.Time // 0001-01-01 00:00:00 +0000 UTC | |
encodedDefaultTime := defaultTime.UnixNano() //gives -6795364578871345152 | |
decodedDefaultTime := time.Unix(0, encodedDefaultTime) | |
if defaultTime != decodedDefaultTime { | |
fmt.Printf("expected: %v, got %v\n", defaultTime, decodedDefaultTime) | |
} | |
} | |
func TestDefaultTimeToUnixAndBackAgain() { | |
var defaultTime time.Time // 0001-01-01 00:00:00 +0000 UTC | |
encodedDefaultTime := defaultTime.Unix() //gives -62135596800 | |
decodedDefaultTime := time.Unix(encodedDefaultTime, 0) | |
if defaultTime != decodedDefaultTime { | |
fmt.Printf("expected: %v, got %v\n", defaultTime, decodedDefaultTime) | |
} | |
} | |
func main() { | |
TestDefaultTimeToUnixNanoAndBackAgain() | |
TestDefaultTimeToUnixAndBackAgain() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- FAIL: TestDefaultTimeToUnixNanoAndBackAgain (0.00s) | |
time_test.go:17: expected: 0001-01-01 00:00:00 +0000 UTC, got 1754-08-30 22:43:41.128654848 +0000 GMT | |
--- FAIL: TestDefaultTimeToUnixAndBackAgain (0.00s) | |
time_test.go:29: expected: 0001-01-01 00:00:00 +0000 UTC, got 0001-01-01 00:00:00 +0000 GMT | |
FAIL | |
FAIL command-line-arguments 0.004s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment