Skip to content

Instantly share code, notes, and snippets.

@sshaw
Created November 30, 2011 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshaw/1410732 to your computer and use it in GitHub Desktop.
Save sshaw/1410732 to your computer and use it in GitHub Desktop.
Harris Timecode
class HarrisTimecode
attr_accessor :hours, :minutes, :seconds, :frames, :encoded
def initialize(encoded)
raise ArgumentError, "Encoded duration invalid: #{encoded}" unless encoded.respond_to?(:to_i)
hex = "%08x" % encoded.to_i
@hours, @minutes, @seconds, @frames = [0,2,4,6].map { |n| hex[n, 2] }
@encoded = encoded
end
def to_s
"#{@hours}:#{@minutes}:#{@seconds}:#{@frames}"
end
end
puts HarrisTimecode.new(140562) # 00:02:25:12
puts HarrisTimecode.new(4096) # 00:00:00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment