mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-24 23:48:29 +02:00
Moves GetTickCount to LazUtils and adds NowUTC to LazUtils
git-svn-id: trunk@33381 -
This commit is contained in:
parent
4f22b9c783
commit
4600e3eb2f
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1761,6 +1761,7 @@ components/lazutils/lazfileutils.pas svneol=native#text/plain
|
|||||||
components/lazutils/lazutf16.pas svneol=native#text/pascal
|
components/lazutils/lazutf16.pas svneol=native#text/pascal
|
||||||
components/lazutils/lazutf8.pas svneol=native#text/plain
|
components/lazutils/lazutf8.pas svneol=native#text/plain
|
||||||
components/lazutils/lazutf8classes.pas svneol=native#text/pascal
|
components/lazutils/lazutf8classes.pas svneol=native#text/pascal
|
||||||
|
components/lazutils/lazutf8sysutils.pas svneol=native#text/plain
|
||||||
components/lazutils/lazutils.lpk svneol=native#text/plain
|
components/lazutils/lazutils.lpk svneol=native#text/plain
|
||||||
components/lazutils/lazutils.pas svneol=native#text/plain
|
components/lazutils/lazutils.pas svneol=native#text/plain
|
||||||
components/lazutils/lazutilsstrconsts.pas svneol=native#text/pascal
|
components/lazutils/lazutilsstrconsts.pas svneol=native#text/pascal
|
||||||
|
122
components/lazutils/lazutf8sysutils.pas
Normal file
122
components/lazutils/lazutf8sysutils.pas
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
unit lazutf8sysutils;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
SysUtils;
|
||||||
|
|
||||||
|
function NowUTC: TDateTime;
|
||||||
|
function GetTickCount: Int64;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes,
|
||||||
|
{$ifdef Windows}
|
||||||
|
Windows
|
||||||
|
{$else}
|
||||||
|
Unix, BaseUnix, UnixUtil
|
||||||
|
{$endif}
|
||||||
|
;
|
||||||
|
|
||||||
|
// ToDo: Move the code to 1 include file per platform
|
||||||
|
{$IFDEF WINDOWS}
|
||||||
|
function NowUTC: TDateTime;
|
||||||
|
var
|
||||||
|
SystemTime: TSystemTime;
|
||||||
|
begin
|
||||||
|
windows.GetSystemTime(SystemTime);
|
||||||
|
result := systemTimeToDateTime(SystemTime);
|
||||||
|
end;
|
||||||
|
|
||||||
|
// GetTickCount64 is better, but we need to check the Windows version to use it
|
||||||
|
function GetTickCount: Int64;
|
||||||
|
begin
|
||||||
|
Result := Windows.GetTickCount();
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$else}
|
||||||
|
{$ifdef UNIX}
|
||||||
|
Const
|
||||||
|
{Date Translation}
|
||||||
|
C1970=2440588;
|
||||||
|
D0 = 1461;
|
||||||
|
D1 = 146097;
|
||||||
|
D2 =1721119;
|
||||||
|
|
||||||
|
Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
|
||||||
|
Var
|
||||||
|
YYear,XYear,Temp,TempMonth : LongInt;
|
||||||
|
Begin
|
||||||
|
Temp:=((JulianDN-D2) shl 2)-1;
|
||||||
|
JulianDN:=Temp Div D1;
|
||||||
|
XYear:=(Temp Mod D1) or 3;
|
||||||
|
YYear:=(XYear Div D0);
|
||||||
|
Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
|
||||||
|
Day:=((Temp Mod 153)+5) Div 5;
|
||||||
|
TempMonth:=Temp Div 153;
|
||||||
|
If TempMonth>=10 Then
|
||||||
|
Begin
|
||||||
|
inc(YYear);
|
||||||
|
dec(TempMonth,12);
|
||||||
|
End;
|
||||||
|
inc(TempMonth,3);
|
||||||
|
Month := TempMonth;
|
||||||
|
Year:=YYear+(JulianDN*100);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
|
||||||
|
{
|
||||||
|
Transforms Epoch time into local time (hour, minute,seconds)
|
||||||
|
}
|
||||||
|
Var
|
||||||
|
DateNum: LongInt;
|
||||||
|
Begin
|
||||||
|
inc(Epoch,TZSeconds);
|
||||||
|
Datenum:=(Epoch Div 86400) + c1970;
|
||||||
|
JulianToGregorian(DateNum,Year,Month,day);
|
||||||
|
Epoch:=Abs(Epoch Mod 86400);
|
||||||
|
Hour:=Epoch Div 3600;
|
||||||
|
Epoch:=Epoch Mod 3600;
|
||||||
|
Minute:=Epoch Div 60;
|
||||||
|
Second:=Epoch Mod 60;
|
||||||
|
End;
|
||||||
|
|
||||||
|
function NowUTC: TDateTime;
|
||||||
|
var
|
||||||
|
tz:timeval;
|
||||||
|
SystemTime: TSystemTime;
|
||||||
|
begin
|
||||||
|
fpgettimeofday(@tz,nil);
|
||||||
|
EpochToLocal(tz.tv_sec,SystemTime.year,SystemTime.month,SystemTime.day,SystemTime.hour,SystemTime.Minute,SystemTime.Second);
|
||||||
|
SystemTime.MilliSecond:=tz.tv_usec div 1000;
|
||||||
|
result := systemTimeToDateTime(SystemTime);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GetTickCount: Int64;
|
||||||
|
var
|
||||||
|
tp: TTimeVal;
|
||||||
|
begin
|
||||||
|
fpgettimeofday(@tp, nil);
|
||||||
|
Result := (tp.tv_sec * 1000) + (tp.tv_usec div 1000);
|
||||||
|
end;
|
||||||
|
{$else}
|
||||||
|
// Not Windows and not UNIX, so just write the most trivial code until we have something besser:
|
||||||
|
function NowUTC: TDateTime;
|
||||||
|
begin
|
||||||
|
Result := Now;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function GetTickCount: Int64;
|
||||||
|
begin
|
||||||
|
Result := Trunc(Now * 24 * 60 * 60 * 1000);
|
||||||
|
end;
|
||||||
|
{$endif}
|
||||||
|
{$endif}
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
@ -4,16 +4,10 @@
|
|||||||
<Name Value="LazUtils"/>
|
<Name Value="LazUtils"/>
|
||||||
<Author Value="Lazarus Team"/>
|
<Author Value="Lazarus Team"/>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="11"/>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
</SearchPaths>
|
</SearchPaths>
|
||||||
<Linking>
|
|
||||||
<Debugging>
|
|
||||||
<GenerateDebugInfo Value="True"/>
|
|
||||||
<DebugInfoType Value="dsAuto"/>
|
|
||||||
</Debugging>
|
|
||||||
</Linking>
|
|
||||||
<Other>
|
<Other>
|
||||||
<CompilerMessages>
|
<CompilerMessages>
|
||||||
<UseMsgFile Value="True"/>
|
<UseMsgFile Value="True"/>
|
||||||
@ -25,7 +19,7 @@
|
|||||||
<Description Value="Useful units for Lazarus packages."/>
|
<Description Value="Useful units for Lazarus packages."/>
|
||||||
<License Value="Modified LGPL-2"/>
|
<License Value="Modified LGPL-2"/>
|
||||||
<Version Major="1"/>
|
<Version Major="1"/>
|
||||||
<Files Count="28">
|
<Files Count="29">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="laz2_dom.pas"/>
|
<Filename Value="laz2_dom.pas"/>
|
||||||
<UnitName Value="laz2_DOM"/>
|
<UnitName Value="laz2_DOM"/>
|
||||||
@ -138,6 +132,10 @@
|
|||||||
<Filename Value="lazutf16.pas"/>
|
<Filename Value="lazutf16.pas"/>
|
||||||
<UnitName Value="lazutf16"/>
|
<UnitName Value="lazutf16"/>
|
||||||
</Item28>
|
</Item28>
|
||||||
|
<Item29>
|
||||||
|
<Filename Value="lazutf8sysutils.pas"/>
|
||||||
|
<UnitName Value="lazutf8sysutils"/>
|
||||||
|
</Item29>
|
||||||
</Files>
|
</Files>
|
||||||
<LazDoc Paths="docs"/>
|
<LazDoc Paths="docs"/>
|
||||||
<i18n>
|
<i18n>
|
||||||
|
@ -11,7 +11,7 @@ uses
|
|||||||
Laz_XMLCfg, Laz_XMLRead, Laz_XMLStreaming, Laz_XMLWrite, LazFileUtils,
|
Laz_XMLCfg, Laz_XMLRead, Laz_XMLStreaming, Laz_XMLWrite, LazFileUtils,
|
||||||
LazFileCache, LUResStrings, LazUTF8, LazDbgLog, paswstring, FileUtil,
|
LazFileCache, LUResStrings, LazUTF8, LazDbgLog, paswstring, FileUtil,
|
||||||
lazutf8classes, Masks, LazUtilsStrConsts, LConvEncoding, lazutf16,
|
lazutf8classes, Masks, LazUtilsStrConsts, LConvEncoding, lazutf16,
|
||||||
LazarusPackageIntf;
|
lazutf8sysutils, LazarusPackageIntf;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ uses
|
|||||||
{$IFDEF UNIX}Unix, {$ENDIF}
|
{$IFDEF UNIX}Unix, {$ENDIF}
|
||||||
{$IFDEF Darwin}MacOSAll, {$ENDIF}
|
{$IFDEF Darwin}MacOSAll, {$ENDIF}
|
||||||
Types, Math, Classes, SysUtils, LCLType, LCLProc, GraphType, InterfaceBase,
|
Types, Math, Classes, SysUtils, LCLType, LCLProc, GraphType, InterfaceBase,
|
||||||
LResources, FileUtil, UTF8Process, Maps, LMessages;
|
LResources, FileUtil, UTF8Process, Maps, LMessages, lazutf8sysutils;
|
||||||
|
|
||||||
{$ifdef Trace}
|
{$ifdef Trace}
|
||||||
{$ASSERTIONS ON}
|
{$ASSERTIONS ON}
|
||||||
@ -71,18 +71,7 @@ function PredefinedClipboardFormat(
|
|||||||
|
|
||||||
function MsgKeyDataToShiftState(KeyData: PtrInt): TShiftState;
|
function MsgKeyDataToShiftState(KeyData: PtrInt): TShiftState;
|
||||||
|
|
||||||
|
function GetTickCount(): Int64;
|
||||||
{$IFDEF WINDOWS}
|
|
||||||
|
|
||||||
{$IFDEF MSWindows}
|
|
||||||
function GetTickCount:DWORD; stdcall; external 'kernel32.dll' name 'GetTickCount';
|
|
||||||
{$ELSE}
|
|
||||||
function GetTickCount:DWORD; stdcall; external KernelDLL name 'GetTickCount';
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
{$ELSE}
|
|
||||||
function GetTickCount: DWord;
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
{$IFDEF DebugLCL}
|
{$IFDEF DebugLCL}
|
||||||
function GetTickStep: DWord;
|
function GetTickStep: DWord;
|
||||||
@ -147,24 +136,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function GetTickCount(): Int64;
|
||||||
{$IFNDEF WINDOWS}
|
|
||||||
function GetTickCount: DWord;
|
|
||||||
{$IFDEF UNIX}
|
|
||||||
var
|
|
||||||
tp: TTimeVal;
|
|
||||||
{$ENDIF}
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF UNIX}
|
Result := lazutf8sysutils.GetTickCount();
|
||||||
if fpgettimeofday(@tp, nil) = 0 then
|
|
||||||
Result := DWord((tp.tv_sec * 1000) + (tp.tv_usec div 1000))
|
|
||||||
else
|
|
||||||
Result := DWord(Trunc(Now * 24 * 60 * 60 * 1000));
|
|
||||||
{$ELSE}
|
|
||||||
Result := DWord(Trunc(Now * 24 * 60 * 60 * 1000));
|
|
||||||
{$ENDIF}
|
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
{$IFDEF DebugLCL}
|
{$IFDEF DebugLCL}
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user