-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.pas
More file actions
75 lines (57 loc) · 1.45 KB
/
Copy pathutils.pas
File metadata and controls
75 lines (57 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
unit Utils;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils;
type
TDuration = TDateTime {Double};
function DurationToStr(ADuration: TDuration): String;
function DurationToStr(ADT1, ADT2: TDateTime): String;
function DurationToStr(ASeconds: Integer): String;
function ExtractIntFromStr(const AStr:string): Integer;
implementation
uses DateUtils, Character;
resourcestring
RSDayUnitShort = 'd';
function DurationToStr(ADuration: TDuration): String;
var
Days: Integer;
begin
Assert(ADuration >= 0, 'Duration can''t be negative');
Days := DaysBetween(0, ADuration);
Result := '';
if Days > 0 then
Result := Result + IntToStr(Days) + RSDayUnitShort + ' ';
Result := Result + FormatDateTime('hh:nn:ss', ADuration);
end;
function DurationToStr(ADT1, ADT2: TDateTime): String;
var
D: TDuration;
begin
D := ADT2 - ADT1;
Result := DurationToStr(D);
end;
function DurationToStr(ASeconds: Integer): String;
var
D: TDuration;
begin
D := IncSecond(0, ASeconds);
Result := DurationToStr(D);
end;
function ExtractIntFromStr(const AStr: string): Integer;
var
S:string='';
C:char {TCharacter};
begin
for c in astr do
begin
if IsDigit(c) then
s:=s+c;
if (not IsDigit(c)) and (not s.IsEmpty) then
Break;
end;
if s='' then
raise Exception.CreateFmt('Can''t extract integer from string "%s"', [astr]);
Result:=StrToInt(s);
end;
end.