github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/time_utils.go (about) 1 package ravendb 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 // TODO: implementation could be improved 9 func durationToTimeSpan(duration time.Duration) string { 10 tm := int64(duration / time.Millisecond) 11 millis := tm % 1000 12 tm = tm / 1000 // seconds 13 seconds := tm % 60 14 tm = tm / 60 // in minutes 15 minutes := tm % 60 16 tm = tm / 60 // in hours 17 hours := tm % 24 18 tm = tm / 24 // in days 19 days := tm 20 21 s := "" 22 23 if days > 0 { 24 s += fmt.Sprintf("%d.", days) 25 } 26 s += fmt.Sprintf("%02d:", hours) 27 s += fmt.Sprintf("%02d:", minutes) 28 s += fmt.Sprintf("%02d", seconds) 29 if millis > 0 { 30 s += fmt.Sprintf(".%03d0000", millis) 31 } 32 return s 33 }