MCPcopy Create free account
hub / github.com/buggregator/server / parseTimestamp

Function parseTimestamp

modules/smtp/api.go:337–352  ·  view source on GitHub ↗

parseTimestamp parses a timestamp from an RFC3339 string, unix-ms integer, or plain float (unix seconds). Returns 0 on failure.

(s string)

Source from the content-addressed store, hash-verified

335// parseTimestamp parses a timestamp from an RFC3339 string, unix-ms integer, or
336// plain float (unix seconds). Returns 0 on failure.
337func parseTimestamp(s string) float64 {
338 if t, err := time.Parse(time.RFC3339Nano, s); err == nil {
339 return unixFloat(t)
340 }
341 if t, err := time.Parse(time.RFC3339, s); err == nil {
342 return unixFloat(t)
343 }
344 if f, err := strconv.ParseFloat(s, 64); err == nil {
345 // Heuristic: values > 1e12 are milliseconds, otherwise seconds.
346 if f > 1e12 {
347 return f / 1000
348 }
349 return f
350 }
351 return 0
352}
353
354// applyFilter filters a slice of events in-memory.
355func applyFilter(events []event.Event, f MessageFilter) []event.Event {

Callers 2

parseFilterFunction · 0.70
TestParseTimestampFunction · 0.70

Calls 2

unixFloatFunction · 0.85
ParseMethod · 0.80

Tested by 1

TestParseTimestampFunction · 0.56