mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-08 11:38:18 +02:00
codetools: moved DateToCfgStr to LazConfigStorage
This commit is contained in:
parent
76d90cf133
commit
67c1c58793
@ -41,7 +41,7 @@ uses
|
|||||||
// Codetools
|
// Codetools
|
||||||
SourceLog, LinkScanner, FileProcs, DirectoryCacher,
|
SourceLog, LinkScanner, FileProcs, DirectoryCacher,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazFileUtils, LazFileCache, Laz2_XMLCfg, LazDbgLog;
|
LazFileUtils, LazFileCache, Laz2_XMLCfg, LazDbgLog, LazConfigStorage;
|
||||||
|
|
||||||
const
|
const
|
||||||
IncludeLinksFileVersion = 2;
|
IncludeLinksFileVersion = 2;
|
||||||
|
@ -44,7 +44,8 @@ uses
|
|||||||
// CodeTools
|
// CodeTools
|
||||||
CodeToolsStrConsts,
|
CodeToolsStrConsts,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazUtilities, LazLoggerBase, LazFileCache, LazFileUtils, LazUTF8, LazStringUtils;
|
LazUtilities, LazLoggerBase, LazFileCache, LazFileUtils, LazUTF8,
|
||||||
|
LazStringUtils, LazConfigStorage;
|
||||||
|
|
||||||
type
|
type
|
||||||
TFPCStreamSeekType = int64;
|
TFPCStreamSeekType = int64;
|
||||||
@ -141,10 +142,10 @@ const
|
|||||||
('', '.inc', '.pp', '.pas');
|
('', '.inc', '.pp', '.pas');
|
||||||
|
|
||||||
// store date locale independent, thread safe
|
// store date locale independent, thread safe
|
||||||
const DateAsCfgStrFormat='YYYYMMDD';
|
const DateAsCfgStrFormat=LazConfigStorage.DateAsCfgStrFormat;
|
||||||
const DateTimeAsCfgStrFormat='YYYY/MM/DD HH:NN:SS';
|
const DateTimeAsCfgStrFormat=LazConfigStorage.DateTimeAsCfgStrFormat;
|
||||||
function DateToCfgStr(const Date: TDateTime; const aFormat: string = DateAsCfgStrFormat): string;
|
function DateToCfgStr(const Date: TDateTime; const aFormat: string = DateAsCfgStrFormat): string; deprecated 'use LazConfigStorage';
|
||||||
function CfgStrToDate(const s: string; out Date: TDateTime; const aFormat: string = DateAsCfgStrFormat): boolean;
|
function CfgStrToDate(const s: string; out Date: TDateTime; const aFormat: string = DateAsCfgStrFormat): boolean; deprecated 'use LazConfigStorage';
|
||||||
|
|
||||||
procedure CTIncreaseChangeStamp(var ChangeStamp: integer); inline;
|
procedure CTIncreaseChangeStamp(var ChangeStamp: integer); inline;
|
||||||
procedure CTIncreaseChangeStamp64(var ChangeStamp: int64); inline;
|
procedure CTIncreaseChangeStamp64(var ChangeStamp: int64); inline;
|
||||||
@ -263,6 +264,17 @@ uses
|
|||||||
Unix;
|
Unix;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
function DateToCfgStr(const Date: TDateTime; const aFormat: string): string;
|
||||||
|
begin
|
||||||
|
Result:=LazConfigStorage.DateToCfgStr(Date,aFormat);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CfgStrToDate(const s: string; out Date: TDateTime;
|
||||||
|
const aFormat: string): boolean;
|
||||||
|
begin
|
||||||
|
Result:=LazConfigStorage.CfgStrToDate(s,Date,aFormat);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure CTIncreaseChangeStamp(var ChangeStamp: integer);
|
procedure CTIncreaseChangeStamp(var ChangeStamp: integer);
|
||||||
begin
|
begin
|
||||||
LazFileCache.LUIncreaseChangeStamp(ChangeStamp);
|
LazFileCache.LUIncreaseChangeStamp(ChangeStamp);
|
||||||
@ -1427,108 +1439,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function DateToCfgStr(const Date: TDateTime; const aFormat: string): string;
|
|
||||||
var
|
|
||||||
NeedDate: Boolean;
|
|
||||||
NeedTime: Boolean;
|
|
||||||
Year: word;
|
|
||||||
Month: word;
|
|
||||||
Day: word;
|
|
||||||
Hour: word;
|
|
||||||
Minute: word;
|
|
||||||
Second: word;
|
|
||||||
MilliSecond: word;
|
|
||||||
p: Integer;
|
|
||||||
w: Word;
|
|
||||||
StartP: Integer;
|
|
||||||
s: String;
|
|
||||||
l: Integer;
|
|
||||||
begin
|
|
||||||
Result:=aFormat;
|
|
||||||
NeedDate:=false;
|
|
||||||
NeedTime:=false;
|
|
||||||
for p:=1 to length(aFormat) do
|
|
||||||
case aFormat[p] of
|
|
||||||
'Y','M','D': NeedDate:=true;
|
|
||||||
'H','N','S','Z': NeedTime:=true;
|
|
||||||
end;
|
|
||||||
if NeedDate then
|
|
||||||
DecodeDate(Date,Year,Month,Day);
|
|
||||||
if NeedTime then
|
|
||||||
DecodeTime(Date,Hour,Minute,Second,MilliSecond);
|
|
||||||
p:=1;
|
|
||||||
while p<=length(aFormat) do begin
|
|
||||||
case aFormat[p] of
|
|
||||||
'Y': w:=Year;
|
|
||||||
'M': w:=Month;
|
|
||||||
'D': w:=Day;
|
|
||||||
'H': w:=Hour;
|
|
||||||
'N': w:=Minute;
|
|
||||||
'S': w:=Second;
|
|
||||||
'Z': w:=MilliSecond;
|
|
||||||
else
|
|
||||||
inc(p);
|
|
||||||
continue;
|
|
||||||
end;
|
|
||||||
StartP:=p;
|
|
||||||
repeat
|
|
||||||
inc(p);
|
|
||||||
until (p>length(aFormat)) or (aFormat[p]<>aFormat[p-1]);
|
|
||||||
l:=p-StartP;
|
|
||||||
s:=IntToStr(w);
|
|
||||||
if length(s)<l then
|
|
||||||
s:=StringOfChar('0',l-length(s))+s
|
|
||||||
else if length(s)>l then
|
|
||||||
raise Exception.Create('date format does not fit');
|
|
||||||
ReplaceSubstring(Result,StartP,l,s);
|
|
||||||
p:=StartP+length(s);
|
|
||||||
end;
|
|
||||||
//debugln('DateToCfgStr "',Result,'"');
|
|
||||||
end;
|
|
||||||
|
|
||||||
function CfgStrToDate(const s: string; out Date: TDateTime;
|
|
||||||
const aFormat: string): boolean;
|
|
||||||
|
|
||||||
procedure AddDecimal(var d: word; c: char); inline;
|
|
||||||
begin
|
|
||||||
d:=d*10+ord(c)-ord('0');
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
Year, Month, Day, Hour, Minute, Second, MilliSecond: word;
|
|
||||||
begin
|
|
||||||
//debugln('CfgStrToDate "',s,'"');
|
|
||||||
if length(s)<>length(aFormat) then begin
|
|
||||||
Date:=0.0;
|
|
||||||
exit(false);
|
|
||||||
end;
|
|
||||||
try
|
|
||||||
Year:=0;
|
|
||||||
Month:=0;
|
|
||||||
Day:=0;
|
|
||||||
Hour:=0;
|
|
||||||
Minute:=0;
|
|
||||||
Second:=0;
|
|
||||||
MilliSecond:=0;
|
|
||||||
for i:=1 to length(aFormat) do begin
|
|
||||||
case aFormat[i] of
|
|
||||||
'Y': AddDecimal(Year,s[i]);
|
|
||||||
'M': AddDecimal(Month,s[i]);
|
|
||||||
'D': AddDecimal(Day,s[i]);
|
|
||||||
'H': AddDecimal(Hour,s[i]);
|
|
||||||
'N': AddDecimal(Minute,s[i]);
|
|
||||||
'S': AddDecimal(Second,s[i]);
|
|
||||||
'Z': AddDecimal(MilliSecond,s[i]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Date:=ComposeDateTime(EncodeDate(Year,Month,Day),EncodeTime(Hour,Minute,Second,MilliSecond));
|
|
||||||
Result:=true;
|
|
||||||
except
|
|
||||||
Result:=false;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure DebugLn(Args: array of const);
|
procedure DebugLn(Args: array of const);
|
||||||
begin
|
begin
|
||||||
LazLoggerBase.Debugln(Args);
|
LazLoggerBase.Debugln(Args);
|
||||||
|
@ -28,7 +28,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
fpcunit, testregistry, contnrs, Classes, SysUtils,
|
fpcunit, testregistry, contnrs, Classes, SysUtils,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazStringUtils,
|
LazStringUtils, LazConfigStorage,
|
||||||
// CodeTools
|
// CodeTools
|
||||||
FileProcs, BasicCodeTools, DefineTemplates;
|
FileProcs, BasicCodeTools, DefineTemplates;
|
||||||
|
|
||||||
|
@ -42,8 +42,7 @@ uses
|
|||||||
Dialogs,
|
Dialogs,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazFileCache, LazFileUtils, LazLoggerBase, LazUTF8, AvgLvlTree, Laz2_XMLCfg,
|
LazFileCache, LazFileUtils, LazLoggerBase, LazUTF8, AvgLvlTree, Laz2_XMLCfg,
|
||||||
// Codetools
|
LazConfigStorage,
|
||||||
FileProcs,
|
|
||||||
// IdeConfig
|
// IdeConfig
|
||||||
DiffPatch, LazConf, RecentListProcs, IdeXmlConfigProcs,
|
DiffPatch, LazConf, RecentListProcs, IdeXmlConfigProcs,
|
||||||
// IdeIntf
|
// IdeIntf
|
||||||
|
@ -20,7 +20,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, typinfo, Laz_AVL_Tree,
|
Classes, SysUtils, typinfo, Laz_AVL_Tree,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
LazLoggerBase, AvgLvlTree;
|
LazLoggerBase, AvgLvlTree, LazStringUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TConfigStorage }
|
{ TConfigStorage }
|
||||||
@ -147,6 +147,12 @@ procedure LoadStringToStringTree(Config: TConfigStorage; const Path: string;
|
|||||||
procedure SaveStringToStringTree(Config: TConfigStorage; const Path: string;
|
procedure SaveStringToStringTree(Config: TConfigStorage; const Path: string;
|
||||||
Tree: TStringToStringTree);
|
Tree: TStringToStringTree);
|
||||||
|
|
||||||
|
// store date locale independent, thread safe
|
||||||
|
const DateAsCfgStrFormat='YYYYMMDD';
|
||||||
|
const DateTimeAsCfgStrFormat='YYYY/MM/DD HH:NN:SS';
|
||||||
|
function DateToCfgStr(const Date: TDateTime; const aFormat: string = DateAsCfgStrFormat): string;
|
||||||
|
function CfgStrToDate(const s: string; out Date: TDateTime; const aFormat: string = DateAsCfgStrFormat): boolean;
|
||||||
|
|
||||||
function CompareConfigMemStorageNames(p1, p2: PChar): integer;
|
function CompareConfigMemStorageNames(p1, p2: PChar): integer;
|
||||||
function CompareConfigMemStorageNodes(Node1, Node2: Pointer): integer;
|
function CompareConfigMemStorageNodes(Node1, Node2: Pointer): integer;
|
||||||
function ComparePCharWithConfigMemStorageNode(aPChar, ANode: Pointer): integer;
|
function ComparePCharWithConfigMemStorageNode(aPChar, ANode: Pointer): integer;
|
||||||
@ -193,6 +199,108 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function DateToCfgStr(const Date: TDateTime; const aFormat: string): string;
|
||||||
|
var
|
||||||
|
NeedDate: Boolean;
|
||||||
|
NeedTime: Boolean;
|
||||||
|
Year: word;
|
||||||
|
Month: word;
|
||||||
|
Day: word;
|
||||||
|
Hour: word;
|
||||||
|
Minute: word;
|
||||||
|
Second: word;
|
||||||
|
MilliSecond: word;
|
||||||
|
p: Integer;
|
||||||
|
w: Word;
|
||||||
|
StartP: Integer;
|
||||||
|
s: String;
|
||||||
|
l: Integer;
|
||||||
|
begin
|
||||||
|
Result:=aFormat;
|
||||||
|
NeedDate:=false;
|
||||||
|
NeedTime:=false;
|
||||||
|
for p:=1 to length(aFormat) do
|
||||||
|
case aFormat[p] of
|
||||||
|
'Y','M','D': NeedDate:=true;
|
||||||
|
'H','N','S','Z': NeedTime:=true;
|
||||||
|
end;
|
||||||
|
if NeedDate then
|
||||||
|
DecodeDate(Date,Year,Month,Day);
|
||||||
|
if NeedTime then
|
||||||
|
DecodeTime(Date,Hour,Minute,Second,MilliSecond);
|
||||||
|
p:=1;
|
||||||
|
while p<=length(aFormat) do begin
|
||||||
|
case aFormat[p] of
|
||||||
|
'Y': w:=Year;
|
||||||
|
'M': w:=Month;
|
||||||
|
'D': w:=Day;
|
||||||
|
'H': w:=Hour;
|
||||||
|
'N': w:=Minute;
|
||||||
|
'S': w:=Second;
|
||||||
|
'Z': w:=MilliSecond;
|
||||||
|
else
|
||||||
|
inc(p);
|
||||||
|
continue;
|
||||||
|
end;
|
||||||
|
StartP:=p;
|
||||||
|
repeat
|
||||||
|
inc(p);
|
||||||
|
until (p>length(aFormat)) or (aFormat[p]<>aFormat[p-1]);
|
||||||
|
l:=p-StartP;
|
||||||
|
s:=IntToStr(w);
|
||||||
|
if length(s)<l then
|
||||||
|
s:=StringOfChar('0',l-length(s))+s
|
||||||
|
else if length(s)>l then
|
||||||
|
raise Exception.Create('date format does not fit');
|
||||||
|
ReplaceSubstring(Result,StartP,l,s);
|
||||||
|
p:=StartP+length(s);
|
||||||
|
end;
|
||||||
|
//debugln('DateToCfgStr "',Result,'"');
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CfgStrToDate(const s: string; out Date: TDateTime;
|
||||||
|
const aFormat: string): boolean;
|
||||||
|
|
||||||
|
procedure AddDecimal(var d: word; c: char); inline;
|
||||||
|
begin
|
||||||
|
d:=d*10+ord(c)-ord('0');
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
i: Integer;
|
||||||
|
Year, Month, Day, Hour, Minute, Second, MilliSecond: word;
|
||||||
|
begin
|
||||||
|
//debugln('CfgStrToDate "',s,'"');
|
||||||
|
if length(s)<>length(aFormat) then begin
|
||||||
|
Date:=0.0;
|
||||||
|
exit(false);
|
||||||
|
end;
|
||||||
|
try
|
||||||
|
Year:=0;
|
||||||
|
Month:=0;
|
||||||
|
Day:=0;
|
||||||
|
Hour:=0;
|
||||||
|
Minute:=0;
|
||||||
|
Second:=0;
|
||||||
|
MilliSecond:=0;
|
||||||
|
for i:=1 to length(aFormat) do begin
|
||||||
|
case aFormat[i] of
|
||||||
|
'Y': AddDecimal(Year,s[i]);
|
||||||
|
'M': AddDecimal(Month,s[i]);
|
||||||
|
'D': AddDecimal(Day,s[i]);
|
||||||
|
'H': AddDecimal(Hour,s[i]);
|
||||||
|
'N': AddDecimal(Minute,s[i]);
|
||||||
|
'S': AddDecimal(Second,s[i]);
|
||||||
|
'Z': AddDecimal(MilliSecond,s[i]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
Date:=ComposeDateTime(EncodeDate(Year,Month,Day),EncodeTime(Hour,Minute,Second,MilliSecond));
|
||||||
|
Result:=true;
|
||||||
|
except
|
||||||
|
Result:=false;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function CompareConfigMemStorageNames(p1, p2: PChar): integer;
|
function CompareConfigMemStorageNames(p1, p2: PChar): integer;
|
||||||
// compare strings till / or #0
|
// compare strings till / or #0
|
||||||
begin
|
begin
|
||||||
|
@ -44,7 +44,7 @@ uses
|
|||||||
Forms,
|
Forms,
|
||||||
// LazUtils
|
// LazUtils
|
||||||
Laz2_XMLCfg, LazFileCache, LazFileUtils, FileUtil, LazUtilities, LazTracer,
|
Laz2_XMLCfg, LazFileCache, LazFileUtils, FileUtil, LazUtilities, LazTracer,
|
||||||
AvgLvlTree,
|
AvgLvlTree, LazConfigStorage,
|
||||||
// Codetools
|
// Codetools
|
||||||
FileProcs, CodeToolManager,
|
FileProcs, CodeToolManager,
|
||||||
// BuildIntf
|
// BuildIntf
|
||||||
|
Loading…
Reference in New Issue
Block a user