Skip to content

Commit

Permalink
add function: Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxu committed Jul 10, 2020
1 parent 3a43fc4 commit 79ed0d6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions durafmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ var (

// Durafmt holds the parsed duration and the original input duration.
type Durafmt struct {
duration time.Duration
input string // Used as reference.
limitN int // Non-zero to limit only first N elements to output.
duration time.Duration
input string // Used as reference.
limitN int // Non-zero to limit only first N elements to output.
limitUnit string // Non-empty to limit max unit
}

Expand All @@ -35,6 +35,10 @@ func (d *Durafmt) LimitFirstN(n int) *Durafmt {
return d
}

func (d *Durafmt) Duration() time.Duration {
return d.duration
}

// Parse creates a new *Durafmt struct, returns error if input is invalid.
func Parse(dinput time.Duration) *Durafmt {
input := dinput.String()
Expand Down Expand Up @@ -95,7 +99,7 @@ func (d *Durafmt) String() string {
var years int64
var shouldConvert = false

remainingSecondsToConvert := int64(d.duration/time.Microsecond)
remainingSecondsToConvert := int64(d.duration / time.Microsecond)

// Convert duration.
if d.limitUnit == "" {
Expand Down

0 comments on commit 79ed0d6

Please sign in to comment.