Skip to content

Commit

Permalink
Allows timecode format hh:mm:ss to be valid (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
tennety committed May 18, 2017
1 parent e8406a2 commit 68484ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/srt/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def id(id_string)
end

def timecode(timecode_string)
mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+)[,.](?<ms>\d+)/)
mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+)[,.]?(?<ms>\d+)?/)
mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["ms"]}".to_f : nil
end

Expand Down
5 changes: 5 additions & 0 deletions spec/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
it "should convert the SRT timecode format to a float representing seconds" do
expect(subject.timecode("01:03:44,200")).to eq(3824.2)
end

it "should handle timecodes with no milliseconds component" do
expect(subject.timecode("01:03:44")).not_to be_nil
expect(subject.timecode("01:03:44")).to eq(3824.0)
end
end

describe ".timespan" do
Expand Down

0 comments on commit 68484ef

Please sign in to comment.