mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-29 12:01:07 -08:00
feat: round timing style
This commit is contained in:
parent
676da9e4d1
commit
8642b7bfd9
|
@ -40,12 +40,13 @@ The [installation guide][install] shows how to include this argument for PowerSh
|
|||
Style specifies the format in which the time will be displayed. The table below shows some example times in each option.
|
||||
|
||||
| format | 0.001s | 2.1s | 3m2.1s | 4h3m2.1s |
|
||||
|-----------|----------------|--------------|---------------|------------------|
|
||||
| --------- | -------------- | ------------ | ------------- | ---------------- |
|
||||
| austin | `1ms` | `2.1s` | `3m 2.1s` | `4h 3m 2.1s` |
|
||||
| roundrock | `1ms` | `2s 100ms` | `3m 2s 100ms` | `4h 3m 2s 100ms` |
|
||||
| dallas | `0.001` | `2.1` | `3:2.1` | `4:3:2.1` |
|
||||
| galveston | `00:00:00` | `00:00:02` | `00:03:02` | `04:03:02` |
|
||||
| houston | `00:00:00.001` | `00:00:02.1` | `00:03:02.1` | `04:03:02.1` |
|
||||
| amarillo | `0.001s` | `2.1s` | `182.1s` | `14,582.1s` |
|
||||
| round | `1ms` | `2s` | `3m` | `4h` |
|
||||
|
||||
[install]: /docs/installation
|
||||
|
|
|
@ -32,6 +32,8 @@ const (
|
|||
Houston DurationStyle = "houston"
|
||||
// Amarillo seconds
|
||||
Amarillo DurationStyle = "amarillo"
|
||||
// Round will round the output of the format
|
||||
Round DurationStyle = "round"
|
||||
|
||||
second = 1000
|
||||
minute = 60000
|
||||
|
@ -78,6 +80,8 @@ func (t *executiontime) formatDuration(ms int64, style DurationStyle) string {
|
|||
return t.formatDurationHouston(ms)
|
||||
case Amarillo:
|
||||
return t.formatDurationAmarillo(ms)
|
||||
case Round:
|
||||
return t.formatDurationRound(ms)
|
||||
default:
|
||||
return fmt.Sprintf("Style: %s is not available", style)
|
||||
}
|
||||
|
@ -175,3 +179,19 @@ func (t *executiontime) formatDurationAmarillo(ms int64) string {
|
|||
|
||||
return result
|
||||
}
|
||||
|
||||
func (t *executiontime) formatDurationRound(ms int64) string {
|
||||
if ms >= day {
|
||||
return fmt.Sprintf("%dd", ms/day)
|
||||
}
|
||||
if ms >= hour {
|
||||
return fmt.Sprintf("%dh", ms/hour%hoursPerDay)
|
||||
}
|
||||
if ms >= minute {
|
||||
return fmt.Sprintf("%dm", ms/minute%secondsPerMinute)
|
||||
}
|
||||
if ms >= second {
|
||||
return fmt.Sprintf("%ds", (ms%minute)/second)
|
||||
}
|
||||
return fmt.Sprintf("%dms", ms%second)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue