Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9017495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:17:21+00:00 2026-06-16T04:17:21+00:00

I’m working on a project that stores data on audio tracks and requires the

  • 0

I’m working on a project that stores data on audio tracks and requires the use of timecodes for the start and end points of the track on the audio. I also need to calculate and display the duration of the track. Eg. a track starts at 0:01:30 and finishes at 0:04:12. So its duration is a total of 2 mins and 42 secs.

The trick is that everything needs to be displayed and handled as timecodes, so in the above example the duration needs to be displayed as 0:02:42.

So my question is how you would store the values? The easiest option would be to store the start and end times as Time in the database. Its very easy to calculate the duration and you can utilise the Rails time helpers in the forms. The only painful part is turning the duration back into a time value for display (since if I supply just the number of seconds to strptime it keeps using the current time to fill in the other fields)

The other option that I considered is storing them as numeric values (as the number of seconds). But then I have to write a lot of code to convert them to and from some type of timecode format and I can’t use the Rails time helpers.

Is there another idea that I haven’t considered? Is there an easy way to calculate and display the duration as a timecode format?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:17:22+00:00Added an answer on June 16, 2026 at 4:17 am

    I would store them as seconds or milliseconds. I’ve been working on a music library manager/audio player in Ruby, and I actually had to write the two methods you would need. It’s not that much code:

      # Helper method to format a number of milliseconds as a string like
      # "1:03:56.555". The only option is :include_milliseconds, true by default. If
      # false, milliseconds won't be included in the formatted string.
      def format_time(milliseconds, options = {})
        ms = milliseconds % 1000
        seconds = (milliseconds / 1000) % 60
        minutes = (milliseconds / 60000) % 60
        hours = milliseconds / 3600000
    
        if ms.zero? || options[:include_milliseconds] == false
          ms_string = ""
        else
          ms_string = ".%03d" % [ms]
        end
    
        if hours > 0
          "%d:%02d:%02d%s" % [hours, minutes, seconds, ms_string]
        else
          "%d:%02d%s" % [minutes, seconds, ms_string]
        end
      end
    
      # Helper method to parse a string like "1:03:56.555" and return the number of
      # milliseconds that time length represents.
      def parse_time(string)
        parts = string.split(":").map(&:to_f)
        parts = [0] + parts if parts.length == 2
        hours, minutes, seconds = parts
        seconds = hours * 3600 + minutes * 60 + seconds
        milliseconds = seconds * 1000
        milliseconds.to_i
      end
    

    It’s written for milliseconds, and would be a lot simpler if it was changed to work with seconds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.