MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / PGWireFormatTimestamp

Function PGWireFormatTimestamp

pkg/sql/sem/tree/pgwire_encode.go:344–381  ·  view source on GitHub ↗

PGWireFormatTimestamp formats t into a format lib/pq understands. If offset is not nil, it will not display the timezone offset.

(t time.Time, offset *time.Location, tmp []byte)

Source from the content-addressed store, hash-verified

342// PGWireFormatTimestamp formats t into a format lib/pq understands.
343// If offset is not nil, it will not display the timezone offset.
344func PGWireFormatTimestamp(t time.Time, offset *time.Location, tmp []byte) (b []byte) {
345 if t == pgdate.TimeInfinity {
346 return []byte("infinity")
347 }
348 if t == pgdate.TimeNegativeInfinity {
349 return []byte("-infinity")
350 }
351
352 format := PGTimeStampFormatNoOffset
353 if offset != nil {
354 format = PGTimeStampFormat
355 if _, offsetSeconds := t.In(offset).Zone(); offsetSeconds%60 != 0 {
356 format += ":00:00"
357 } else if offsetSeconds%3600 != 0 {
358 format += ":00"
359 }
360 }
361
362 // Need to send dates before 0001 A.D. with " BC" suffix, instead of the
363 // minus sign preferred by Go.
364 // Beware, "0000" in ISO is "1 BC", "-0001" is "2 BC" and so on
365 if offset != nil {
366 t = t.In(offset)
367 }
368
369 bc := false
370 if t.Year() <= 0 {
371 // flip year sign, and add 1, e.g: "0" will be "1", and "-10" will be "11"
372 t = t.AddDate((-t.Year())*2+1, 0, 0)
373 bc = true
374 }
375
376 b = t.AppendFormat(tmp, format)
377 if bc {
378 b = append(b, " BC"...)
379 }
380 return b
381}

Callers 2

FormatMethod · 0.85
FormatMethod · 0.85

Calls 2

InMethod · 0.80
AppendFormatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…