in client/utils.go [102:154]
func parseLongToDateWithPrecision(timestamp int64, zone *time.Location, precision string) string {
var divisor int64
var digits int
switch precision {
case MILLISECOND:
divisor = 1000
digits = 3
case MICROSECOND:
divisor = 1_000_000
digits = 6
case NANOSECOND:
divisor = 1_000_000_000
digits = 9
default:
return ""
}
quotient := timestamp / divisor
remainder := timestamp % divisor
if timestamp < 0 && remainder != 0 {
quotient--
remainder += divisor
}
t := time.Unix(quotient, 0).In(zone)
year, month, day := t.Date()
hour, min, sec := t.Clock()
_, offset := t.Zone()
offsetSeconds := offset
sign := "+"
if offsetSeconds < 0 {
sign = "-"
offsetSeconds = -offsetSeconds
}
hours := offsetSeconds / 3600
minutes := (offsetSeconds % 3600) / 60
zoneOffset := fmt.Sprintf("%s%02d:%02d", sign, hours, minutes)
if offset == 0 {
zoneOffset = "Z"
}
formatStr := fmt.Sprintf("%%0%dd", digits)
fraction := fmt.Sprintf(formatStr, remainder)
isoStr := fmt.Sprintf("%04d-%02d-%02dT%02d:%02d:%02d.%s%s",
year, month, day, hour, min, sec, fraction, zoneOffset)
return isoStr
}