Skip to content

Commit

Permalink
jsontime: add duration create helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Jan 8, 2025
1 parent cedd234 commit 0493223
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jsontime/duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type Seconds struct {
time.Duration
}

func S(dur time.Duration) Seconds {
return Seconds{Duration: dur}
}

func (s Seconds) MarshalJSON() ([]byte, error) {
return []byte(strconv.FormatInt(int64(s.Seconds()), 10)), nil
}
Expand All @@ -54,6 +58,10 @@ type Milliseconds struct {
time.Duration
}

func MS(dur time.Duration) Milliseconds {
return Milliseconds{Duration: dur}
}

func (s Milliseconds) MarshalJSON() ([]byte, error) {
return []byte(strconv.FormatInt(s.Milliseconds(), 10)), nil
}
Expand Down

0 comments on commit 0493223

Please sign in to comment.