Skip to content

Commit

Permalink
Merge pull request #137 from BreakTos/main
Browse files Browse the repository at this point in the history
Functions for time durations
  • Loading branch information
chasefleming authored Apr 6, 2024
2 parents 3849233 + 490853d commit 742990b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions styles/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,13 @@ func ViewportMin(value int) string {
func ViewportMax(value int) string {
return strconv.Itoa(value) + "vmax"
}

// Seconds returns a string representation of the given float64 or int
func Seconds(value float64) string {
return strconv.FormatFloat(value, 'f', 2, 64) + "s"
}

// Milliseconds returns a string representation of the given int
func Milliseconds(value int) string {
return strconv.Itoa(value) + "ms"
}
17 changes: 16 additions & 1 deletion styles/utils_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package styles

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestMerge(t *testing.T) {
Expand Down Expand Up @@ -151,3 +152,17 @@ func TestViewportMax(t *testing.T) {
assert.Equal(t, "50vmax", ViewportMax(50))
assert.Equal(t, "25vmax", ViewportMax(25))
}

func TestSeconds(t *testing.T) {
assert.Equal(t, "100.00s", Seconds(100.00))
assert.Equal(t, "1.25s", Seconds(1.25))
assert.Equal(t, "0.00s", Seconds(0))
assert.Equal(t, "0.25s", Seconds(0.25))
}

func TestMilliseconds(t *testing.T) {
assert.Equal(t, "25ms", Milliseconds(25))
assert.Equal(t, "1ms", Milliseconds(1))
assert.Equal(t, "0ms", Milliseconds(0))
assert.Equal(t, "110ms", Milliseconds(110))
}

0 comments on commit 742990b

Please sign in to comment.