From 49c308974a739221972c337a19aa5788f10528ec Mon Sep 17 00:00:00 2001 From: Avishek Gulshan Date: Fri, 26 Nov 2021 21:14:47 +0530 Subject: [PATCH] updating duration.String() to handle duration less than a second --- go.mod | 2 +- mpd/duration.go | 8 +++++--- mpd/duration_test.go | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 2c7c90c..c52ad31 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/EurosportDigital/go-dash/v3 go 1.13 -replace github.com/zencoder/go-dash/v3 => github.com/EurosportDigital/go-dash v3.0.2 +replace github.com/zencoder/go-dash/v3 => github.com/EurosportDigital/go-dash v3.0.3 diff --git a/mpd/duration.go b/mpd/duration.go index 8ebc870..4546efa 100644 --- a/mpd/duration.go +++ b/mpd/duration.go @@ -54,13 +54,15 @@ func (d *Duration) String() string { if u < uint64(time.Second) { // Special case: if duration is smaller than a second, // use smaller units, like 1.2ms - var prec int + //var prec int w-- buf[w] = 'S' w-- if u == 0 { return "PT0S" } + t := time.Duration(*d) + return fmt.Sprintf("PT%vS", t.Seconds()) /* switch { case u < uint64(Millisecond): @@ -75,8 +77,8 @@ func (d *Duration) String() string { buf[w] = 'm' } */ - w, u = fmtFrac(buf[:w], u, prec) - w = fmtInt(buf[:w], u) + // w, u = fmtFrac(buf[:w], u, prec) + // w = fmtInt(buf[:w], u) } else { w-- buf[w] = 'S' diff --git a/mpd/duration_test.go b/mpd/duration_test.go index edd29b6..493439e 100644 --- a/mpd/duration_test.go +++ b/mpd/duration_test.go @@ -13,6 +13,7 @@ func TestDuration(t *testing.T) { "0s": "PT0S", "6m16s": "PT6M16S", "1.97s": "PT1.97S", + "0.960s": "PT0.96S", } for ins, ex := range in { timeDur, err := time.ParseDuration(ins)