Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to multiply a duration by a duration?

Tags:

go

To my surprise, this compiled

fmt.Println(time.Second * time.Second)

The result is nonsense

277777h46m40s

It doesn't make any sense to multiply a duration by duration and get another duration.

What's going on?

like image 724
Colonel Panic Avatar asked Sep 06 '25 12:09

Colonel Panic


1 Answers

The Duration type is simply an int64 representing the duration as a nanosecond count

type Duration int64

A Duration represents the elapsed time between two instants as an int64 nanosecond count.

So multiplying one duration by another gives the result of multiplying the number of nanoseconds in each. In my example, this gives a billion billion nanoseconds, or 277777h46m40s. Nonsense, but well-defined!

like image 90
Colonel Panic Avatar answered Sep 10 '25 02:09

Colonel Panic