parseTimestamp converts a Sentry timestamp (float64 epoch seconds or ISO string) to an RFC3339 string.
(ts json.Number)
| 149 | |
| 150 | // parseTimestamp converts a Sentry timestamp (float64 epoch seconds or ISO string) to an RFC3339 string. |
| 151 | func parseTimestamp(ts json.Number) *string { |
| 152 | if ts == "" { |
| 153 | return nil |
| 154 | } |
| 155 | |
| 156 | // Try as float (epoch seconds). |
| 157 | if f, err := strconv.ParseFloat(string(ts), 64); err == nil { |
| 158 | sec := int64(f) |
| 159 | nsec := int64((f - float64(sec)) * 1e9) |
| 160 | t := time.Unix(sec, nsec).UTC().Format(time.RFC3339Nano) |
| 161 | return &t |
| 162 | } |
| 163 | |
| 164 | // Try as string (ISO 8601). |
| 165 | s := string(ts) |
| 166 | if _, err := time.Parse(time.RFC3339, s); err == nil { |
| 167 | return &s |
| 168 | } |
| 169 | |
| 170 | return &s |
| 171 | } |
no test coverage detected