MCPcopy
hub / github.com/go-sql-driver/mysql / TestDateTime

Function TestDateTime

driver_test.go:906–1021  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

904}
905
906func TestDateTime(t *testing.T) {
907 afterTime := func(t time.Time, d string) time.Time {
908 dur, err := time.ParseDuration(d)
909 if err != nil {
910 panic(err)
911 }
912 return t.Add(dur)
913 }
914 // NOTE: MySQL rounds DATETIME(x) up - but that's not included in the tests
915 format := "2006-01-02 15:04:05.999999"
916 t0 := time.Time{}
917 tstr0 := "0000-00-00 00:00:00.000000"
918 testcases := []timeTests{
919 {"DATE", format[:10], []timeTest{
920 {t: time.Date(2011, 11, 20, 0, 0, 0, 0, time.UTC)},
921 {t: t0, s: tstr0[:10]},
922 }},
923 {"DATETIME", format[:19], []timeTest{
924 {t: time.Date(2011, 11, 20, 21, 27, 37, 0, time.UTC)},
925 {t: t0, s: tstr0[:19]},
926 }},
927 {"DATETIME(0)", format[:21], []timeTest{
928 {t: time.Date(2011, 11, 20, 21, 27, 37, 0, time.UTC)},
929 {t: t0, s: tstr0[:19]},
930 }},
931 {"DATETIME(1)", format[:21], []timeTest{
932 {t: time.Date(2011, 11, 20, 21, 27, 37, 100000000, time.UTC)},
933 {t: t0, s: tstr0[:21]},
934 }},
935 {"DATETIME(6)", format, []timeTest{
936 {t: time.Date(2011, 11, 20, 21, 27, 37, 123456000, time.UTC)},
937 {t: t0, s: tstr0},
938 }},
939 {"TIME", format[11:19], []timeTest{
940 {t: afterTime(t0, "12345s")},
941 {s: "!-12:34:56"},
942 {s: "!-838:59:59"},
943 {s: "!838:59:59"},
944 {t: t0, s: tstr0[11:19]},
945 }},
946 {"TIME(0)", format[11:19], []timeTest{
947 {t: afterTime(t0, "12345s")},
948 {s: "!-12:34:56"},
949 {s: "!-838:59:59"},
950 {s: "!838:59:59"},
951 {t: t0, s: tstr0[11:19]},
952 }},
953 {"TIME(1)", format[11:21], []timeTest{
954 {t: afterTime(t0, "12345600ms")},
955 {s: "!-12:34:56.7"},
956 {s: "!-838:59:58.9"},
957 {s: "!838:59:58.9"},
958 {t: t0, s: tstr0[11:21]},
959 }},
960 {"TIME(6)", format[11:], []timeTest{
961 {t: afterTime(t0, "1234567890123000ns")},
962 {s: "!-12:34:56.789012"},
963 {s: "!-838:59:58.999999"},

Callers

nothing calls this directly

Calls 6

runTestsFunction · 0.85
ScanMethod · 0.80
runMethod · 0.80
QueryMethod · 0.45
NextMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected