Skip to content

add methods for getting start and end time in seconds #3

@jronallo

Description

@jronallo

It would be convenient to have a cue return a timestamp of a start or end time converted into seconds. The methods might be #start_seconds and #end_seconds. Here's a method which converts a WebVTT formatted timestamp into seconds:

def jump_time(timestamp)
  time_parts = timestamp.split(':')
  seconds = time_parts.pop
  minutes = time_parts.pop
  hours   = time_parts.first if !time_parts.blank?
  total_seconds = hours.to_i.hours.seconds
  total_seconds += minutes.to_i.minutes.seconds
  total_seconds += seconds.split('.').first.to_i
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions