github.com/grahambrereton-form3/tilt@v0.10.18/internal/hud/format.go (about)

     1  package hud
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  	"time"
     7  )
     8  
     9  func formatBuildDuration(d time.Duration) string {
    10  	hours := int(d.Hours())
    11  	if hours > 0 {
    12  		return fmt.Sprintf("%dh", hours)
    13  	}
    14  
    15  	minutes := int(d.Minutes())
    16  	if minutes > 0 {
    17  		return fmt.Sprintf("%dm", minutes)
    18  	}
    19  
    20  	seconds := d.Seconds()
    21  	if seconds >= 9.95 {
    22  		return fmt.Sprintf("%ds", int(math.Round(seconds)))
    23  	}
    24  
    25  	fractionalSeconds := float64(d) / float64(time.Second)
    26  	return fmt.Sprintf("%0.1fs", fractionalSeconds)
    27  }
    28  
    29  func formatDeployAge(d time.Duration) string {
    30  	switch {
    31  	case d.Seconds() < 5:
    32  		return "<5s"
    33  	case d.Seconds() < 15:
    34  		return "<15s"
    35  	case d.Seconds() < 30:
    36  		return "<30s"
    37  	case d.Seconds() < 45:
    38  		return "<45s"
    39  	case d.Minutes() < 1:
    40  		return "<1m"
    41  	case d.Hours() < 1:
    42  		return fmt.Sprintf("%dm", int(d.Minutes()))
    43  	default:
    44  		return fmt.Sprintf("%dh", int(d.Hours()))
    45  	}
    46  }