MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / FormatBinaryTime

Function FormatBinaryTime

IceFireDB-SQLProxy/pkg/mysql/mysql/util.go:311–342  ·  view source on GitHub ↗
(n int, data []byte)

Source from the content-addressed store, hash-verified

309}
310
311func FormatBinaryTime(n int, data []byte) ([]byte, error) {
312 if n == 0 {
313 return []byte("0000-00-00"), nil
314 }
315
316 var sign byte
317 if data[0] == 1 {
318 sign = byte('-')
319 }
320
321 switch n {
322 case 8:
323 return fmt.Appendf(nil,
324 "%c%02d:%02d:%02d",
325 sign,
326 uint16(data[1])*24+uint16(data[5]),
327 data[6],
328 data[7],
329 ), nil
330 case 12:
331 return fmt.Appendf(nil,
332 "%c%02d:%02d:%02d.%06d",
333 sign,
334 uint16(data[1])*24+uint16(data[5]),
335 data[6],
336 data[7],
337 binary.LittleEndian.Uint32(data[8:12]),
338 ), nil
339 default:
340 return nil, errors.Errorf("invalid time packet length %d", n)
341 }
342}
343
344var (
345 DONTESCAPE = byte(255)

Callers 1

ParseBinaryMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected