Get rid of FracTime and friends

This commit is contained in:
2018-11-19 22:56:31 +01:00
parent db67e68078
commit 83e16c72f2
3 changed files with 93 additions and 116 deletions
+74 -68
View File
@@ -3,6 +3,7 @@ package tests
import (
"fmt"
"testing"
"time"
"github.com/localhots/bocadillo/mysql"
)
@@ -61,96 +62,96 @@ func TestTimestamp(t *testing.T) {
tbl := suite.createTable(mysql.ColumnTypeTimestamp, "", attrNone)
defer tbl.drop(t)
vals := []string{
"0000-00-00T00:00:00Z",
vals := []time.Time{
parseTime("0000-00-00T00:00:00Z"),
// This is the lowest I could get
// Spec says 1970-01-01 00:00:01 should be supported
"1970-01-01T01:00:01Z",
"1975-01-01T00:00:01Z",
"1985-01-01T00:00:01Z",
"1999-12-31T23:59:59Z",
"2018-11-08T19:26:00Z",
"2038-01-19T03:14:07Z",
"2038-01-19T04:14:07Z", // Should be outside supported range? 2038-01-19 03:14:07
parseTime("1970-01-01T01:00:01Z"),
parseTime("1975-01-01T00:00:01Z"),
parseTime("1985-01-01T00:00:01Z"),
parseTime("1999-12-31T23:59:59Z"),
parseTime("2018-11-08T19:26:00Z"),
parseTime("2038-01-19T03:14:07Z"),
parseTime("2038-01-19T04:14:07Z"), // Should be outside supported range? 2038-01-19 03:14:07
}
for _, v := range vals {
t.Run(v, func(t *testing.T) {
t.Run(v.Format(time.RFC3339Nano), func(t *testing.T) {
suite.insertAndCompare(t, tbl, v)
})
}
}
func TestDatetime(t *testing.T) {
inputs := map[string][]string{
inputs := map[string][]time.Time{
"0": {
"0000-00-00T00:00:00Z",
"1000-01-01T00:00:00Z",
"1975-01-01T00:00:01Z",
"1985-01-01T00:00:01Z",
"1999-12-31T23:59:59Z",
"2018-11-08T19:26:00Z",
"2038-01-19T03:14:07Z",
"9999-12-31T23:59:59Z",
parseTime("0000-00-00T00:00:00Z"),
parseTime("1000-01-01T00:00:00Z"),
parseTime("1975-01-01T00:00:01Z"),
parseTime("1985-01-01T00:00:01Z"),
parseTime("1999-12-31T23:59:59Z"),
parseTime("2018-11-08T19:26:00Z"),
parseTime("2038-01-19T03:14:07Z"),
parseTime("9999-12-31T23:59:59Z"),
},
"1": {
"0000-00-00T00:00:00.0Z",
"1000-01-01T00:00:00.1Z",
"1975-01-01T00:00:01.1Z",
"1985-01-01T00:00:01.1Z",
"1999-12-31T23:59:59.1Z",
"2018-11-08T19:26:00.1Z",
"2038-01-19T03:14:07.1Z",
"9999-12-31T23:59:59.1Z",
parseTime("0000-00-00T00:00:00.0Z"),
parseTime("1000-01-01T00:00:00.1Z"),
parseTime("1975-01-01T00:00:01.1Z"),
parseTime("1985-01-01T00:00:01.1Z"),
parseTime("1999-12-31T23:59:59.1Z"),
parseTime("2018-11-08T19:26:00.1Z"),
parseTime("2038-01-19T03:14:07.1Z"),
parseTime("9999-12-31T23:59:59.1Z"),
},
"2": {
"0000-00-00T00:00:00.00Z",
"1000-01-01T00:00:00.22Z",
"1975-01-01T00:00:01.22Z",
"1985-01-01T00:00:01.22Z",
"1999-12-31T23:59:59.22Z",
"2018-11-08T19:26:00.22Z",
"2038-01-19T03:14:07.22Z",
"9999-12-31T23:59:59.22Z",
parseTime("0000-00-00T00:00:00.00Z"),
parseTime("1000-01-01T00:00:00.22Z"),
parseTime("1975-01-01T00:00:01.22Z"),
parseTime("1985-01-01T00:00:01.22Z"),
parseTime("1999-12-31T23:59:59.22Z"),
parseTime("2018-11-08T19:26:00.22Z"),
parseTime("2038-01-19T03:14:07.22Z"),
parseTime("9999-12-31T23:59:59.22Z"),
},
"3": {
"0000-00-00T00:00:00.000Z",
"1000-01-01T00:00:00.333Z",
"1975-01-01T00:00:01.333Z",
"1985-01-01T00:00:01.333Z",
"1999-12-31T23:59:59.333Z",
"2018-11-08T19:26:00.333Z",
"2038-01-19T03:14:07.333Z",
"9999-12-31T23:59:59.333Z",
parseTime("0000-00-00T00:00:00.000Z"),
parseTime("1000-01-01T00:00:00.333Z"),
parseTime("1975-01-01T00:00:01.333Z"),
parseTime("1985-01-01T00:00:01.333Z"),
parseTime("1999-12-31T23:59:59.333Z"),
parseTime("2018-11-08T19:26:00.333Z"),
parseTime("2038-01-19T03:14:07.333Z"),
parseTime("9999-12-31T23:59:59.333Z"),
},
"4": {
"0000-00-00T00:00:00.0000Z",
"1000-01-01T00:00:00.4444Z",
"1975-01-01T00:00:01.4444Z",
"1985-01-01T00:00:01.4444Z",
"1999-12-31T23:59:59.4444Z",
"2018-11-08T19:26:00.4444Z",
"2038-01-19T03:14:07.4444Z",
"9999-12-31T23:59:59.4444Z",
parseTime("0000-00-00T00:00:00.0000Z"),
parseTime("1000-01-01T00:00:00.4444Z"),
parseTime("1975-01-01T00:00:01.4444Z"),
parseTime("1985-01-01T00:00:01.4444Z"),
parseTime("1999-12-31T23:59:59.4444Z"),
parseTime("2018-11-08T19:26:00.4444Z"),
parseTime("2038-01-19T03:14:07.4444Z"),
parseTime("9999-12-31T23:59:59.4444Z"),
},
"5": {
"0000-00-00T00:00:00.00000Z",
"1000-01-01T00:00:00.55555Z",
"1975-01-01T00:00:01.55555Z",
"1985-01-01T00:00:01.55555Z",
"1999-12-31T23:59:59.55555Z",
"2018-11-08T19:26:00.55555Z",
"2038-01-19T03:14:07.55555Z",
"9999-12-31T23:59:59.55555Z",
parseTime("0000-00-00T00:00:00.00000Z"),
parseTime("1000-01-01T00:00:00.55555Z"),
parseTime("1975-01-01T00:00:01.55555Z"),
parseTime("1985-01-01T00:00:01.55555Z"),
parseTime("1999-12-31T23:59:59.55555Z"),
parseTime("2018-11-08T19:26:00.55555Z"),
parseTime("2038-01-19T03:14:07.55555Z"),
parseTime("9999-12-31T23:59:59.55555Z"),
},
"6": {
"0000-00-00T00:00:00.000000Z",
"1000-01-01T00:00:00.666666Z",
"1975-01-01T00:00:01.666666Z",
"1985-01-01T00:00:01.666666Z",
"1999-12-31T23:59:59.666666Z",
"2018-11-08T19:26:00.666666Z",
"2038-01-19T03:14:07.666666Z",
"9999-12-31T23:59:59.666666Z",
parseTime("0000-00-00T00:00:00.000000Z"),
parseTime("1000-01-01T00:00:00.666666Z"),
parseTime("1975-01-01T00:00:01.666666Z"),
parseTime("1985-01-01T00:00:01.666666Z"),
parseTime("1999-12-31T23:59:59.666666Z"),
parseTime("2018-11-08T19:26:00.666666Z"),
parseTime("2038-01-19T03:14:07.666666Z"),
parseTime("9999-12-31T23:59:59.666666Z"),
},
}
for length, vals := range inputs {
@@ -159,10 +160,15 @@ func TestDatetime(t *testing.T) {
defer tbl.drop(t)
for _, v := range vals {
t.Run(v, func(t *testing.T) {
t.Run(v.Format(time.RFC3339Nano), func(t *testing.T) {
suite.insertAndCompare(t, tbl, v)
})
}
})
}
}
func parseTime(str string) time.Time {
t, _ := time.Parse(str, time.RFC3339Nano)
return t
}