MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestEncodeDecodeTime

Function TestEncodeDecodeTime

server/types_test.go:1212–1282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1210}
1211
1212func TestEncodeDecodeTime(t *testing.T) {
1213 tests := []struct {
1214 name string
1215 input interface{}
1216 expectMicros int64
1217 expectStr string
1218 }{
1219 {
1220 "midnight",
1221 time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC),
1222 0,
1223 "00:00:00",
1224 },
1225 {
1226 "10:30:00",
1227 time.Date(1, 1, 1, 10, 30, 0, 0, time.UTC),
1228 10*3600000000 + 30*60000000,
1229 "10:30:00",
1230 },
1231 {
1232 "23:59:59",
1233 time.Date(1, 1, 1, 23, 59, 59, 0, time.UTC),
1234 23*3600000000 + 59*60000000 + 59*1000000,
1235 "23:59:59",
1236 },
1237 {
1238 "12:00:00.500000",
1239 time.Date(1, 1, 1, 12, 0, 0, 500000000, time.UTC), // 500ms = 500000µs
1240 12*3600000000 + 500000,
1241 "12:00:00.500000",
1242 },
1243 {
1244 "string 10:30:00",
1245 "10:30:00",
1246 10*3600000000 + 30*60000000,
1247 "10:30:00",
1248 },
1249 }
1250
1251 for _, tt := range tests {
1252 t.Run(tt.name, func(t *testing.T) {
1253 encoded := encodeTime(tt.input)
1254 if encoded == nil {
1255 t.Fatalf("encodeTime(%v) returned nil", tt.input)
1256 }
1257 if len(encoded) != 8 {
1258 t.Fatalf("encodeTime(%v) length = %d, want 8", tt.input, len(encoded))
1259 }
1260 gotMicros := int64(binary.BigEndian.Uint64(encoded))
1261 if gotMicros != tt.expectMicros {
1262 t.Errorf("encodeTime(%v) = %d micros, want %d", tt.input, gotMicros, tt.expectMicros)
1263 }
1264
1265 decoded, err := decodeTime(encoded)
1266 if err != nil {
1267 t.Fatalf("decodeTime error: %v", err)
1268 }
1269 if decoded != tt.expectStr {

Callers

nothing calls this directly

Calls 4

encodeTimeFunction · 0.85
decodeTimeFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected