Files
2026-03-02 17:40:35 +08:00

16 lines
399 B
Go

package utils
import "time"
// RoundDownTo10Minutes rounds down a time to the nearest 10-minute mark
// Example: 10:07:30 -> 10:00:00, 10:15:45 -> 10:10:00, 10:20:00 -> 10:20:00
func RoundDownTo10Minutes(t time.Time) time.Time {
minutes := t.Minute()
roundedMinutes := (minutes / 10) * 10
return time.Date(
t.Year(), t.Month(), t.Day(),
t.Hour(), roundedMinutes, 0, 0,
t.Location(),
)
}