Skip to content

Commit

Permalink
Fixes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed Jul 3, 2019
1 parent 1738826 commit ff5bb75
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions segment-duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -37,7 +38,7 @@ func segmentDuration(p *powerline) {

hasPrecision := strings.Index(durationValue, ".") != -1

d, err := time.ParseDuration(durationValue + "s")
durationFloat, err := strconv.ParseFloat(durationValue, 64)
if err != nil {
p.appendSegment("duration", segment{
content: fmt.Sprintf("Failed to convert '%s' to a number", *p.args.Duration),
Expand All @@ -47,9 +48,11 @@ func segmentDuration(p *powerline) {
return
}

if d > 0 {
duration := time.Duration(durationFloat) * time.Second

if duration > 0 {
var content string
ns := d.Nanoseconds()
ns := duration.Nanoseconds()
if ns > hours {
hrs := ns / hours
ns -= hrs * hours
Expand Down

0 comments on commit ff5bb75

Please sign in to comment.