Skip to content

total time components #85

Description

@Soviut

It would be really handy to be able to get the totalSeconds, totalMinutes, etc. from a duration.

const { totalSeconds } = parse(duration)

I have a use case for this where we're normalizing the length of different media to seconds and one of the formats is an ISO duration. Currently I have to parse the duration, then convert all the components to seconds then add them up.

const durationToSeconds = (duration: string): number => {
  const parsed = parse(duration)

  const totalSeconds =
    (parsed.hours ?? 0) * 3600 +
    (parsed.minutes ?? 0) * 60 +
    (parsed.seconds ?? 0)

  return totalSeconds ?? 0
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions