program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Types, SysUtils, Math, StrUtils;
type
TCDTimecode =
record
Frames: Integer;
function GetAsString:
String;
procedure SetAsString(
const tc:
String);
end;
const
fps = 75;
FramesPerHour = SecsPerHour * fps;
FramesPerMin = SecsPerMin * fps;
{ TCDTimecode }
function TCDTimecode.GetAsString:
String;
const
sign:
array [Boolean]
of String = ('
+', '
-');
var
t: Cardinal;
h, m, s, f: Word;
neg: Boolean;
begin
neg := Frames<0;
t := abs(Frames);
h := t
div FramesPerHour;
dec(t, h * FramesPerHour);
divmod(t, FramesPerMin, m, s);
divmod(Cardinal(s), fps, s, f);
Result := Format('
%s%.2d:%.2d:%.2d:%.2d', [sign[neg], h, m, s, f])
end;
procedure TCDTimecode.SetAsString(
const tc:
String);
var
List: TStringDynArray;
begin
List := SplitString(tc, '
:');
if length(List) = 4
then begin
Frames := StrToInt(List[0]);
Frames := Frames * MinsPerHour + StrToInt(List[1]);
Frames := Frames * SecsPerMin + StrToInt(List[2]);
Frames := Frames * fps + StrToInt(List[3]);
end
else
raise Exception.CreateFmt('
invalid timecode "%s"', [tc]);
end;
var
t1, t2: TCDTimecode;
begin
try
t1.SetAsString('
03:00:00:12');
t2.SetAsString('
01:00:00:12');
dec(t1.Frames, t2.Frames);
writeln(t1.GetAsString);
t1.SetAsString('
03:00:00:12');
t2.SetAsString('
01:00:00:13');
dec(t1.Frames, t2.Frames);
writeln(t1.GetAsString);
readln;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
end.