Skip to content

Commit

Permalink
updating duration.String() to handle duration less than a second
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishek-Gulshan committed Nov 26, 2021
1 parent 97b5557 commit 49c3089
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions mpd/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'
Expand Down
1 change: 1 addition & 0 deletions mpd/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 49c3089

Please sign in to comment.