Skip to content

Commit

Permalink
Fix typo and style (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille authored May 7, 2024
1 parent 6ce0e84 commit 58dbc8d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
)

// Parse attempts to parse the given duration string into a *Duration,
// if parsing fails an error is returned instead
// if parsing fails an error is returned instead.
func Parse(d string) (*Duration, error) {
if !strings.Contains(d, "P") {
return nil, ErrUnexpectedInput
Expand Down Expand Up @@ -145,7 +145,7 @@ func Parse(d string) (*Duration, error) {

// FromTimeDuration converts the given time.Duration into duration.Duration.
// Note that for *Duration's with period values of a month or year that the duration becomes a bit fuzzy
// since obviously those things vary month to month and year to year
// since obviously those things vary month to month and year to year.
func FromTimeDuration(d time.Duration) *Duration {
duration := &Duration{}
if d == 0 {
Expand Down Expand Up @@ -186,21 +186,21 @@ func FromTimeDuration(d time.Duration) *Duration {
return duration
}

// Format formats the given time.Duration into an ISO 8601 duration string (e.g. P1DT6H5M),
// Format formats the given time.Duration into an ISO 8601 duration string (e.g., P1DT6H5M),
// negative durations are prefixed with a minus sign, for a zero duration "PT0S" is returned.
// Note that for *Duration's with period values of a month or year that the duration becomes a bit fuzzy
// since obviously those things vary month to month and year to year
// since obviously those things vary month to month and year to year.
func Format(d time.Duration) string {
return FromTimeDuration(d).String()
}

// ToTimeDuration converts the *Duration to the standard library's time.Duration.
// Note that for *Duration's with period values of a month or year that the duration becomes a bit fuzzy
// since obviously those things vary month to month and year to year
// since obviously those things vary month to month and year to year.
func (duration *Duration) ToTimeDuration() time.Duration {
var timeDuration time.Duration

// zero checks are here to avoid unnecessary math operations, on a durations such as `PT5M`
// zero checks are here to avoid unnecessary math operations, on a duration such as `PT5M`
if duration.Years != 0 {
timeDuration += time.Duration(math.Round(duration.Years * nsPerYear))
}
Expand Down

0 comments on commit 58dbc8d

Please sign in to comment.