|
@@ -21,7 +21,7 @@ interface
|
|
|
|
|
|
{$ifndef FPUNONE}
|
|
{$ifndef FPUNONE}
|
|
uses
|
|
uses
|
|
- SysUtils, Math, Types;
|
|
|
|
|
|
+ SysUtils, Math;
|
|
|
|
|
|
{ ---------------------------------------------------------------------
|
|
{ ---------------------------------------------------------------------
|
|
Various constants
|
|
Various constants
|
|
@@ -329,6 +329,13 @@ Function EncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word
|
|
Procedure DecodeDateMonthWeek(const AValue: TDateTime; out AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word);
|
|
Procedure DecodeDateMonthWeek(const AValue: TDateTime; out AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word);
|
|
Function TryEncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word; out AValue: TDateTime): Boolean;
|
|
Function TryEncodeDateMonthWeek(const AYear, AMonth, AWeekOfMonth, ADayOfWeek: Word; out AValue: TDateTime): Boolean;
|
|
|
|
|
|
|
|
+{ ---------------------------------------------------------------------
|
|
|
|
+ Encode time interval, allowing hours>24
|
|
|
|
+ ---------------------------------------------------------------------}
|
|
|
|
+
|
|
|
|
+function TryEncodeTimeInterval(Hour, Min, Sec, MSec:word; Out Time : TDateTime) : boolean;
|
|
|
|
+function EncodeTimeInterval(Hour, Minute, Second, MilliSecond:word): TDateTime;
|
|
|
|
+
|
|
{ ---------------------------------------------------------------------
|
|
{ ---------------------------------------------------------------------
|
|
Replace given element with supplied value.
|
|
Replace given element with supplied value.
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
@@ -440,13 +447,13 @@ end;
|
|
Simple trimming functions.
|
|
Simple trimming functions.
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
-Function DateOf(const AValue: TDateTime): TDateTime;
|
|
|
|
|
|
+Function DateOf(const AValue: TDateTime): TDateTime; inline;
|
|
begin
|
|
begin
|
|
Result:=Trunc(AValue);
|
|
Result:=Trunc(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function TimeOf(const AValue: TDateTime): TDateTime;
|
|
|
|
|
|
+Function TimeOf(const AValue: TDateTime): TDateTime; inline;
|
|
begin
|
|
begin
|
|
Result:=Frac(Avalue);
|
|
Result:=Frac(Avalue);
|
|
end;
|
|
end;
|
|
@@ -458,24 +465,14 @@ end;
|
|
|
|
|
|
|
|
|
|
Function IsInLeapYear(const AValue: TDateTime): Boolean;
|
|
Function IsInLeapYear(const AValue: TDateTime): Boolean;
|
|
-
|
|
|
|
-Var
|
|
|
|
- D,Y,M : Word;
|
|
|
|
-
|
|
|
|
begin
|
|
begin
|
|
- DecodeDate(AValue,Y,M,D);
|
|
|
|
- Result:=IsLeapYear(Y);
|
|
|
|
|
|
+ Result:=IsLeapYear(YearOf(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function IsPM(const AValue: TDateTime): Boolean;
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- H,M,S,MS : Word;
|
|
|
|
-
|
|
|
|
|
|
+Function IsPM(const AValue: TDateTime): Boolean; inline;
|
|
begin
|
|
begin
|
|
- DecodeTime(AValue,H,M,S,MS);
|
|
|
|
- Result:=(H>=12);
|
|
|
|
|
|
+ Result:=(HourOf(AValue)>=12);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -535,13 +532,8 @@ end;
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
Function WeeksInYear(const AValue: TDateTime): Word;
|
|
Function WeeksInYear(const AValue: TDateTime): Word;
|
|
-
|
|
|
|
-Var
|
|
|
|
- Y,M,D : Word;
|
|
|
|
-
|
|
|
|
begin
|
|
begin
|
|
- DecodeDate(AValue,Y,M,D);
|
|
|
|
- Result:=WeeksInAYear(Y);
|
|
|
|
|
|
+ Result:=WeeksInAYear(YearOf(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -559,13 +551,8 @@ end;
|
|
|
|
|
|
|
|
|
|
Function DaysInYear(const AValue: TDateTime): Word;
|
|
Function DaysInYear(const AValue: TDateTime): Word;
|
|
-
|
|
|
|
-Var
|
|
|
|
- Y,M,D : Word;
|
|
|
|
-
|
|
|
|
begin
|
|
begin
|
|
- DecodeDate(AValue,Y,M,D);
|
|
|
|
- Result:=DaysPerYear[IsLeapYear(Y)];
|
|
|
|
|
|
+ Result:=DaysPerYear[IsLeapYear(YearOf(AValue))];
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -597,27 +584,27 @@ end;
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
|
|
-Function Today: TDateTime;
|
|
|
|
|
|
+Function Today: TDateTime; inline;
|
|
begin
|
|
begin
|
|
- Result:=Date;
|
|
|
|
|
|
+ Result:=Date();
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
Function Yesterday: TDateTime;
|
|
Function Yesterday: TDateTime;
|
|
begin
|
|
begin
|
|
- Result:=Date-1;
|
|
|
|
|
|
+ Result:=Date()-1;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function Tomorrow: TDateTime;
|
|
|
|
|
|
+Function Tomorrow: TDateTime;
|
|
begin
|
|
begin
|
|
- Result:=Date+1;
|
|
|
|
|
|
+ Result:=Date()+1;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
Function IsToday(const AValue: TDateTime): Boolean;
|
|
Function IsToday(const AValue: TDateTime): Boolean;
|
|
begin
|
|
begin
|
|
- Result:=IsSameDay(AValue,Date);
|
|
|
|
|
|
+ Result:=IsSameDay(AValue,Date());
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -669,7 +656,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WeekOf(const AValue: TDateTime): Word;
|
|
|
|
|
|
+Function WeekOf(const AValue: TDateTime): Word; inline;
|
|
begin
|
|
begin
|
|
Result:=WeekOfTheYear(AValue);
|
|
Result:=WeekOfTheYear(AValue);
|
|
end;
|
|
end;
|
|
@@ -711,7 +698,7 @@ Var
|
|
H,N,MS : Word;
|
|
H,N,MS : Word;
|
|
|
|
|
|
begin
|
|
begin
|
|
- DecodeTime(AVAlue,H,N,Result,MS);
|
|
|
|
|
|
+ DecodeTime(AValue,H,N,Result,MS);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -731,24 +718,14 @@ end;
|
|
|
|
|
|
|
|
|
|
Function StartOfTheYear(const AValue: TDateTime): TDateTime;
|
|
Function StartOfTheYear(const AValue: TDateTime): TDateTime;
|
|
-
|
|
|
|
-Var
|
|
|
|
- Y,M,D : Word;
|
|
|
|
-
|
|
|
|
begin
|
|
begin
|
|
- DecodeDate(AValue,Y,M,D);
|
|
|
|
- Result:=EncodeDate(Y,1,1);
|
|
|
|
|
|
+ Result:=EncodeDate(YearOf(AValue),1,1);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
Function EndOfTheYear(const AValue: TDateTime): TDateTime;
|
|
Function EndOfTheYear(const AValue: TDateTime): TDateTime;
|
|
-
|
|
|
|
-Var
|
|
|
|
- Y,M,D : Word;
|
|
|
|
-
|
|
|
|
begin
|
|
begin
|
|
- DecodeDate(AValue,Y,M,D);
|
|
|
|
- Result:=EncodeDateTime(Y,12,31,23,59,59,999);
|
|
|
|
|
|
+ Result:=EncodeDateTime(YearOf(AValue),12,31,23,59,59,999);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -791,7 +768,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function StartOfAMonth(const AYear, AMonth: Word): TDateTime;
|
|
|
|
|
|
+Function StartOfAMonth(const AYear, AMonth: Word): TDateTime; inline;
|
|
begin
|
|
begin
|
|
Result:=EncodeDate(AYear,AMonth,1);
|
|
Result:=EncodeDate(AYear,AMonth,1);
|
|
end;
|
|
end;
|
|
@@ -827,13 +804,13 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function StartOfAWeek(const AYear, AWeekOfYear: Word): TDateTime; // ADayOFWeek 1
|
|
|
|
|
|
+Function StartOfAWeek(const AYear, AWeekOfYear: Word): TDateTime; inline; // ADayOFWeek 1
|
|
begin
|
|
begin
|
|
Result:=StartOfAWeek(AYear,AWeekOfYear,1)
|
|
Result:=StartOfAWeek(AYear,AWeekOfYear,1)
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function EndOfAWeek(const AYear, AWeekOfYear: Word; const ADayOfWeek: Word): TDateTime;
|
|
|
|
|
|
+Function EndOfAWeek(const AYear, AWeekOfYear: Word; const ADayOfWeek: Word): TDateTime; inline;
|
|
begin
|
|
begin
|
|
Result := EndOfTheDay(EncodeDateWeek(AYear, AWeekOfYear, ADayOfWeek));
|
|
Result := EndOfTheDay(EncodeDateWeek(AYear, AWeekOfYear, ADayOfWeek));
|
|
end;
|
|
end;
|
|
@@ -850,7 +827,7 @@ end;
|
|
Start/End of day functions.
|
|
Start/End of day functions.
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
-Function StartOfTheDay(const AValue: TDateTime): TDateTime;
|
|
|
|
|
|
+Function StartOfTheDay(const AValue: TDateTime): TDateTime; inline;
|
|
begin
|
|
begin
|
|
StartOfTheDay:=Trunc(Avalue);
|
|
StartOfTheDay:=Trunc(Avalue);
|
|
end;
|
|
end;
|
|
@@ -867,7 +844,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function StartOfADay(const AYear, AMonth, ADay: Word): TDateTime;
|
|
|
|
|
|
+Function StartOfADay(const AYear, AMonth, ADay: Word): TDateTime; inline;
|
|
begin
|
|
begin
|
|
Result:=EncodeDate(AYear,AMonth,ADay);
|
|
Result:=EncodeDate(AYear,AMonth,ADay);
|
|
end;
|
|
end;
|
|
@@ -879,7 +856,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function EndOfADay(const AYear, AMonth, ADay: Word): TDateTime;
|
|
|
|
|
|
+Function EndOfADay(const AYear, AMonth, ADay: Word): TDateTime; inline;
|
|
begin
|
|
begin
|
|
Result:=EndOfTheDay(EncodeDate(AYear,AMonth,ADay));
|
|
Result:=EndOfTheDay(EncodeDate(AYear,AMonth,ADay));
|
|
end;
|
|
end;
|
|
@@ -897,13 +874,9 @@ end;
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
|
|
-Function MonthOfTheYear(const AValue: TDateTime): Word;
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- Y,D : Word;
|
|
|
|
-
|
|
|
|
|
|
+Function MonthOfTheYear(const AValue: TDateTime): Word; inline;
|
|
begin
|
|
begin
|
|
- DecodeDate(AValue,Y,Result,D);
|
|
|
|
|
|
+ Result:=MonthOf(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1116,13 +1089,9 @@ end;
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
|
|
-Function HourOfTheDay(const AValue: TDateTime): Word;
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- M,S,MS : Word;
|
|
|
|
-
|
|
|
|
|
|
+Function HourOfTheDay(const AValue: TDateTime): Word; inline;
|
|
begin
|
|
begin
|
|
- DecodeTime(AValue,Result,M,S,MS);
|
|
|
|
|
|
+ Result:=HourOf(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1163,13 +1132,9 @@ end;
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
|
|
-Function MinuteOfTheHour(const AValue: TDateTime): Word;
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- H,S,MS : Word;
|
|
|
|
-
|
|
|
|
|
|
+Function MinuteOfTheHour(const AValue: TDateTime): Word; inline;
|
|
begin
|
|
begin
|
|
- DecodeTime(AValue,H,Result,S,MS);
|
|
|
|
|
|
+ Result:=MinuteOf(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1199,13 +1164,9 @@ end;
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
|
|
|
|
-Function SecondOfTheMinute(const AValue: TDateTime): Word;
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- H,M,MS : Word;
|
|
|
|
-
|
|
|
|
|
|
+Function SecondOfTheMinute(const AValue: TDateTime): Word; inline;
|
|
begin
|
|
begin
|
|
- DecodeTime(AValue,H,M,Result,MS);
|
|
|
|
|
|
+ Result:=SecondOf(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
@@ -1223,62 +1184,58 @@ end;
|
|
Part of second functions.
|
|
Part of second functions.
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
-Function MilliSecondOfTheSecond(const AValue: TDateTime): Word;
|
|
|
|
-
|
|
|
|
-Var
|
|
|
|
- H,M,S : Word;
|
|
|
|
-
|
|
|
|
|
|
+Function MilliSecondOfTheSecond(const AValue: TDateTime): Word; inline;
|
|
begin
|
|
begin
|
|
- DecodeTime(AValue,H,M,S,Result);
|
|
|
|
|
|
+ Result:=MilliSecondOf(AValue);
|
|
end;
|
|
end;
|
|
|
|
|
|
{ ---------------------------------------------------------------------
|
|
{ ---------------------------------------------------------------------
|
|
Range checking functions.
|
|
Range checking functions.
|
|
---------------------------------------------------------------------}
|
|
---------------------------------------------------------------------}
|
|
|
|
|
|
-Function WithinPastYears(const ANow, AThen: TDateTime; const AYears: Integer): Boolean;
|
|
|
|
|
|
+Function WithinPastYears(const ANow, AThen: TDateTime; const AYears: Integer): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=YearsBetween(ANow,AThen)<=AYears;
|
|
Result:=YearsBetween(ANow,AThen)<=AYears;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastMonths(const ANow, AThen: TDateTime; const AMonths: Integer): Boolean;
|
|
|
|
|
|
+Function WithinPastMonths(const ANow, AThen: TDateTime; const AMonths: Integer): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=MonthsBetween(ANow,AThen)<=AMonths;
|
|
Result:=MonthsBetween(ANow,AThen)<=AMonths;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastWeeks(const ANow, AThen: TDateTime; const AWeeks: Integer): Boolean;
|
|
|
|
|
|
+Function WithinPastWeeks(const ANow, AThen: TDateTime; const AWeeks: Integer): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=WeeksBetween(ANow,AThen)<=AWeeks;
|
|
Result:=WeeksBetween(ANow,AThen)<=AWeeks;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastDays(const ANow, AThen: TDateTime; const ADays: Integer): Boolean;
|
|
|
|
|
|
+Function WithinPastDays(const ANow, AThen: TDateTime; const ADays: Integer): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=DaysBetween(ANow,AThen)<=ADays;
|
|
Result:=DaysBetween(ANow,AThen)<=ADays;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastHours(const ANow, AThen: TDateTime; const AHours: Int64): Boolean;
|
|
|
|
|
|
+Function WithinPastHours(const ANow, AThen: TDateTime; const AHours: Int64): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=HoursBetween(ANow,AThen)<=AHours;
|
|
Result:=HoursBetween(ANow,AThen)<=AHours;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastMinutes(const ANow, AThen: TDateTime; const AMinutes: Int64): Boolean;
|
|
|
|
|
|
+Function WithinPastMinutes(const ANow, AThen: TDateTime; const AMinutes: Int64): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=MinutesBetween(ANow,AThen)<=AMinutes;
|
|
Result:=MinutesBetween(ANow,AThen)<=AMinutes;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean;
|
|
|
|
|
|
+Function WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=SecondsBetween(ANow,Athen)<=ASeconds;
|
|
Result:=SecondsBetween(ANow,Athen)<=ASeconds;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function WithinPastMilliSeconds(const ANow, AThen: TDateTime; const AMilliSeconds: Int64): Boolean;
|
|
|
|
|
|
+Function WithinPastMilliSeconds(const ANow, AThen: TDateTime; const AMilliSeconds: Int64): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=MilliSecondsBetween(ANow,AThen)<=AMilliSeconds;
|
|
Result:=MilliSecondsBetween(ANow,AThen)<=AMilliSeconds;
|
|
end;
|
|
end;
|
|
@@ -1742,6 +1699,23 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+{ ---------------------------------------------------------------------
|
|
|
|
+ Encode time interval, allowing hours>24
|
|
|
|
+ ---------------------------------------------------------------------}
|
|
|
|
+
|
|
|
|
+function TryEncodeTimeInterval(Hour, Min, Sec, MSec: word; out Time: TDateTime): boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:= (Min<60) and (Sec<60) and (MSec<1000);
|
|
|
|
+ If Result then
|
|
|
|
+ Time:=TDateTime(cardinal(Hour)*3600000+cardinal(Min)*60000+cardinal(Sec)*1000+MSec)/MSecsPerDay;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+function EncodeTimeInterval(Hour, Minute, Second, MilliSecond: word): TDateTime;
|
|
|
|
+begin
|
|
|
|
+ If not TryEncodeTimeInterval(Hour,Minute,Second,MilliSecond,Result) then
|
|
|
|
+ Raise EConvertError.CreateFmt('%d:%d:%d.%d is not a valid time specification',
|
|
|
|
+ [Hour,Minute,Second,MilliSecond]);
|
|
|
|
+end;
|
|
|
|
|
|
{ ---------------------------------------------------------------------
|
|
{ ---------------------------------------------------------------------
|
|
Replace given element with supplied value.
|
|
Replace given element with supplied value.
|
|
@@ -1888,7 +1862,7 @@ begin
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
|
|
-Function SameDate(const A, B: TDateTime): Boolean;
|
|
|
|
|
|
+Function SameDate(const A, B: TDateTime): Boolean; inline;
|
|
begin
|
|
begin
|
|
Result:=Trunc(A)=Trunc(B);
|
|
Result:=Trunc(A)=Trunc(B);
|
|
end;
|
|
end;
|