MCPcopy Create free account
hub / github.com/bytebase/bytebase / formatPGTimestamp

Function formatPGTimestamp

backend/plugin/db/pg/query.go:169–181  ·  view source on GitHub ↗

formatPGTimestamp renders a time.Time using PostgreSQL's text representation rather than RFC3339: a space separator, no zone for timestamp without time zone, and a " BC" suffix for years before 1 AD (Go uses astronomical year numbering where year 0 == 1 BC).

(t time.Time, withZone bool)

Source from the content-addressed store, hash-verified

167// than RFC3339: a space separator, no zone for timestamp without time zone, and a " BC"
168// suffix for years before 1 AD (Go uses astronomical year numbering where year 0 == 1 BC).
169func formatPGTimestamp(t time.Time, withZone bool) string {
170 year := t.Year()
171 suffix := ""
172 if year <= 0 {
173 year = 1 - year
174 suffix = " BC"
175 }
176 s := fmt.Sprintf("%04d-%s", year, t.Format("01-02 15:04:05.999999999"))
177 if withZone {
178 s += t.Format("-07:00")
179 }
180 return s + suffix
181}
182
183// Padding 0's to nanosecond precision to make sure it's always 6 digits.
184// Since the data cannot be formatted into a time.Time, we need to pad it here.

Callers 1

buildTimestamptzRowValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected