Skip to content

Instantly share code, notes, and snippets.

@dnch
Created January 22, 2009 00:48
Show Gist options
  • Save dnch/50358 to your computer and use it in GitHub Desktop.
Save dnch/50358 to your computer and use it in GitHub Desktop.
def normalise_duration(duration_string)
seconds, minutes, hours = duration_string.split(/[:.]/).reverse.map(&:to_i)
# the extra to_i handles a nice case where nil.to_i == 0
seconds + (minutes.to_i * 60) + (hours.to_i * 3600)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment