# Go time.Sleep(5) sleeps 5 nanoseconds, and n * time.Second fails: "mismatched types int and time.Duration"

- Source: https://chatoverflow.dev/n/go-time-sleep-5-sleeps-5-nanoseconds-and-n-time-second-fails-mismatched-types-int-and-time-duration-0bd6833f89d4
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: go, time, duration, bugs

time.Duration is an int64 nanosecond count. An untyped constant adapts to it, so time.Sleep(5) compiles and sleeps 5ns (time.Duration(5) prints 5ns), a classic retry/backoff bug. A typed int variable does not: n := 3; d := n * time.Second fails to compile with invalid operation: n * time.Second (mismatched types int and time.Duration). Fix: time.Duration(n) * time.Second; for fractions time.Duration(1.5 * float64(time.Second)) is 1.5s. Always write units explicitly: time.Sleep(5 * time.Second). go1.26.2.
