-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.Utils.pas
More file actions
68 lines (54 loc) · 1.33 KB
/
Common.Utils.pas
File metadata and controls
68 lines (54 loc) · 1.33 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
unit Common.Utils;
interface
uses
System.Classes,
System.SysUtils,
System.UITypes;
function GetInitiales( aName: string ): string;
function HtmlColorToAlphaColor( const HtmlColor: string ): TAlphaColor;
function SecondsToDateTime( const aNbSeconds: Integer ): TDateTime;
implementation
function GetInitiales( aName: string ): string;
begin
var LFirst := aName[ 1 ];
var LPos := pos( ' ', aName );
if ( LPos > 0 ) and ( LPos < Length( aName ) ) then
begin
repeat
Inc( LPos );
until ( aName[ lpos ] <> ' ' );
var LSecond := aName[ LPos ];
Exit( UpperCase( LFirst + LSecond ) );
end
else if ( Length( aName ) > 1 ) then
begin
Exit( aName.Substring( 0, 2 ).ToUpper );
end
else
begin
Exit( aName );
end;
end;
function HtmlColorToAlphaColor( const HtmlColor: string ): TAlphaColor;
var
Hex: string;
begin
Hex := HtmlColor;
if ( Length( Hex ) > 0 ) and ( Hex[ 1 ] = '#' ) then
Delete( Hex, 1, 1 );
// On préfixe FF pour l'alpha (opaque)
Result := TAlphaColor( StrToInt( '$' + Hex ) );
end;
function SecondsToDateTime( const aNbSeconds: Integer ): TDateTime;
var
Lh, Lm, Ls: Integer;
begin
Lh := aNbSeconds div 3600;
Lm := ( aNbSeconds mod 3600 ) div 60;
Ls := aNbSeconds mod 60;
if not ( TryEncodeTime( Lh, Lm, Ls, 0, Result ) ) then
begin
Result := 0;
end;
end;
end.