Toot

Written by Mark Gritter on 2025-01-17 at 05:55

Go's zero time is year 1, not 1970 or something Unix-y like that. That's fine.

Except:

func main() {

origin := time.Time{}

t := time.Date(2025, 1, 16, 4, 0, 0, 0, time.UTC)

d := t.Sub(origin)

t2 := origin.Add(d)

fmt.Println(t2)

}

results in 0293-04-11 23:47:16.854775807 +0000 UTC

https://go.dev/play/p/turgQXfyJG-

There's obviously an integer overflow happening here and it's too late in the day for me to figure out how to work around it.

What I need to do is truncate times to a 64-hour or 256-hour boundary. Our existing Go code truncates relative to Go's zero time. TimescaleDB truncates relative to 2001-01-01, or 2001-01-03 in some cases when calculating buckets. It seems challenging to write code that handles both, if the invariant t.Sub(origin).Add(origin) == t does not hold.

[#]golang

=> More informations about this toot | View the thread | More toots from markgritter@mathstodon.xyz

Mentions

Tags

=> View golang tag

Proxy Information
Original URL
gemini://mastogem.picasoft.net/toot/113842147094769354
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
242.605345 milliseconds
Gemini-to-HTML Time
0.891247 milliseconds

This content has been proxied by September (3851b).