MCPcopy Index your code
hub / github.com/google/go-github / formatRateReset

Function formatRateReset

github/github.go:2004–2024  ·  view source on GitHub ↗

formatRateReset formats d to look like "[rate reset in 2s]" or "[rate reset in 87m02s]" for the positive durations. And like "[rate limit was reset 87m02s ago]" for the negative cases.

(d time.Duration)

Source from the content-addressed store, hash-verified

2002// "[rate reset in 87m02s]" for the positive durations. And like "[rate limit was reset 87m02s ago]"
2003// for the negative cases.
2004func formatRateReset(d time.Duration) string {
2005 isNegative := d < 0
2006 if isNegative {
2007 d *= -1
2008 }
2009 secondsTotal := int(0.5 + d.Seconds())
2010 minutes := secondsTotal / 60
2011 seconds := secondsTotal - minutes*60
2012
2013 var timeString string
2014 if minutes > 0 {
2015 timeString = fmt.Sprintf("%vm%02ds", minutes, seconds)
2016 } else {
2017 timeString = fmt.Sprintf("%vs", seconds)
2018 }
2019
2020 if isNegative {
2021 return fmt.Sprintf("[rate limit was reset %v ago]", timeString)
2022 }
2023 return fmt.Sprintf("[rate reset in %v]", timeString)
2024}
2025
2026func sleepUntilResetWithBuffer(ctx context.Context, reset time.Time) error {
2027 buffer := time.Second

Callers 2

ErrorMethod · 0.85
TestFormatRateResetFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFormatRateResetFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…