Skip to content

Commit

Permalink
feat(executiontime): add galvestonms
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Jul 21, 2022
1 parent a4ef99a commit 8426f81
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/segments/executiontime.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
Dallas DurationStyle = "dallas"
// Galveston hour
Galveston DurationStyle = "galveston"
// Galveston hour
GalvestonMs DurationStyle = "galvestonms"
// Houston hour and milliseconds
Houston DurationStyle = "houston"
// Amarillo seconds
Expand Down Expand Up @@ -80,6 +82,8 @@ func (t *Executiontime) formatDuration(style DurationStyle) string {
return t.formatDurationDallas()
case Galveston:
return t.formatDurationGalveston()
case GalvestonMs:
return t.formatDurationGalvestonMs()
case Houston:
return t.formatDurationHouston()
case Amarillo:
Expand Down Expand Up @@ -149,6 +153,12 @@ func (t *Executiontime) formatDurationGalveston() string {
return result
}

func (t *Executiontime) formatDurationGalvestonMs() string {
millies := t.Ms % second
result := fmt.Sprintf("%02d:%02d:%02d:%03d", t.Ms/hour, t.Ms/minute%minutesPerHour, t.Ms%minute/second, millies)
return result
}

func (t *Executiontime) formatDurationHouston() string {
milliseconds := ".0"
if t.Ms%second > 0 {
Expand Down
26 changes: 26 additions & 0 deletions src/segments/executiontime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,32 @@ func TestExecutionTimeFormatGalveston(t *testing.T) {
}
}

func TestExecutionTimeFormatGalvestonMs(t *testing.T) {
cases := []struct {
Input string
Expected string
}{
{Input: "0.001s", Expected: "00:00:00:001"},
{Input: "0.1s", Expected: "00:00:00:100"},
{Input: "1s", Expected: "00:00:01:000"},
{Input: "2.1s", Expected: "00:00:02:100"},
{Input: "1m", Expected: "00:01:00:000"},
{Input: "3m2.1s", Expected: "00:03:02:100"},
{Input: "1h", Expected: "01:00:00:000"},
{Input: "4h3m2.1s", Expected: "04:03:02:100"},
{Input: "124h3m2.1s", Expected: "124:03:02:100"},
{Input: "124h3m2.0s", Expected: "124:03:02:000"},
}

for _, tc := range cases {
duration, _ := time.ParseDuration(tc.Input)
executionTime := &Executiontime{}
executionTime.Ms = duration.Milliseconds()
output := executionTime.formatDurationGalvestonMs()
assert.Equal(t, tc.Expected, output, tc.Input)
}
}

func TestExecutionTimeFormatHouston(t *testing.T) {
cases := []struct {
Input string
Expand Down
1 change: 1 addition & 0 deletions themes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,7 @@
"roundrock",
"dallas",
"galveston",
"galvestonms",
"houston",
"amarillo",
"round"
Expand Down
21 changes: 11 additions & 10 deletions website/docs/segments/executiontime.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,22 @@ The installation guide shows how to include this argument for PowerShell and Zsh

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 2s` | `4h 3m` |
| 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` |
| galvestonms | `00:00:00:001` | `00:00:02:100` | `00:03:02:100` | `04:03:02:100` |
| 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 2s` | `4h 3m` |

## Template ([info][templates])

:::note default template

``` template
```template
{{ .FormattedMs }}
```

Expand Down

0 comments on commit 8426f81

Please sign in to comment.