From 0008d31ae6fa88f3ef8180f735e4d31b6dbce51d Mon Sep 17 00:00:00 2001 From: siddharth ravikumar Date: Thu, 21 Jul 2022 17:40:33 -0400 Subject: time: `durationToSeconds` -> `Duration` --- time/time.go | 2 +- time/time_test.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'time') diff --git a/time/time.go b/time/time.go index 97bd3d5..a7821d9 100644 --- a/time/time.go +++ b/time/time.go @@ -18,7 +18,7 @@ var durationRegex = regexp.MustCompile(`PT(([0-9]{0,2})?H)?(([0-9]{0,2})?M)?(([0 // Recognizes durations in this format: PT3H4M60S // // [1]: https://en.wikipedia.org/wiki/ISO_8601#Durations -func durationToSeconds(duration string) (int, error) { +func Duration(duration string) (int, error) { m := durationRegex.FindStringSubmatch(duration) if m == nil || len(m) == 0 { return 0, fmt.Errorf("duration invalid: %v", duration) diff --git a/time/time_test.go b/time/time_test.go index d55783e..48ef75e 100644 --- a/time/time_test.go +++ b/time/time_test.go @@ -6,7 +6,7 @@ package time import "testing" func TestDurationToSeconds(t *testing.T) { - secs, err := durationToSeconds("PT3H4M60S") + secs, err := Duration("PT3H4M60S") if err != nil { t.Errorf("failed: %v", err) return @@ -16,7 +16,7 @@ func TestDurationToSeconds(t *testing.T) { return } - secs, err = durationToSeconds("PT4M60S") + secs, err = Duration("PT4M60S") if err != nil { t.Errorf("failed: %v", err) return @@ -26,7 +26,7 @@ func TestDurationToSeconds(t *testing.T) { return } - secs, err = durationToSeconds("PT12H") + secs, err = Duration("PT12H") if err != nil { t.Errorf("failed: %v", err) return @@ -36,7 +36,7 @@ func TestDurationToSeconds(t *testing.T) { return } - secs, err = durationToSeconds("PT1H") + secs, err = Duration("PT1H") if err != nil { t.Errorf("failed: %v", err) return @@ -46,7 +46,7 @@ func TestDurationToSeconds(t *testing.T) { return } - secs, err = durationToSeconds("PT2H") + secs, err = Duration("PT2H") if err != nil { t.Errorf("failed: %v", err) return @@ -56,7 +56,7 @@ func TestDurationToSeconds(t *testing.T) { return } - secs, err = durationToSeconds("PT45M") + secs, err = Duration("PT45M") if err != nil { t.Errorf("failed: %v", err) return -- cgit v1.2.3