dateutil.inc implement new functions
Original Reporter info from Mantis: turrican
-
Reporter name: Enrique Fuentes
Description:
Index: packages/rtl-objpas/src/inc/dateutil.inc
===================================================================
--- packages/rtl-objpas/src/inc/dateutil.inc (revision 38731)
+++ packages/rtl-objpas/src/inc/dateutil.inc (working copy)
@@ -248,7 +248,11 @@
Function WithinPastMinutes(const ANow, AThen: TDateTime; const AMinutes: Int64): Boolean;
Function WithinPastSeconds(const ANow, AThen: TDateTime; const ASeconds: Int64): Boolean;
Function WithinPastMilliSeconds(const ANow, AThen: TDateTime; const AMilliSeconds: Int64): Boolean;
+function DateTimeInRange(ADateTime: TDateTime; AStartDateTime, AEndDateTime: TDateTime; aInclusive: Boolean = True): Boolean;
+function DateInRange(ADate: TDate; AStartDate, AEndDate: TDate; AInclusive: Boolean = True): Boolean;
+function TimeInRange(ATime: TTime; AStartTime, AEndTime: TTime; AInclusive: Boolean = True): Boolean;
+
{ ---------------------------------------------------------------------
Period functions.
---------------------------------------------------------------------}
@@ -1258,7 +1262,42 @@
Result:=MilliSecondsBetween(ANow,AThen)<=AMilliSeconds;
end;
+function DateTimeInRange(ADateTime: TDateTime; AStartDateTime, AEndDateTime: TDateTime; aInclusive: Boolean = True): Boolean;
+begin
+ if aInclusive then
+ Result := (AStartDateTime <= ADateTime) and (ADateTime <= AEndDateTime)
+ else
+ Result := (AStartDateTime < ADateTime) and (ADateTime < AEndDateTime);
+end;
+function TimeInRange(ATime: TTime; AStartTime, AEndTime: TTime; AInclusive: Boolean = True): Boolean;
+var
+ LTime, LStartTime, LEndTime: TTime;
+begin
+ LTime := TimeOf(ATime);
+ LStartTime := TimeOf(AStartTime);
+ LEndTime := TimeOF(AEndTime);
+
+ if LEndTime < LStartTime then
+ if AInclusive then
+ Result := (LStartTime <= LTime) or (LTime <= LEndTime)
+ else
+ Result := (LStartTime < LTime) or (LTime < LEndTime)
+ else
+ if AInclusive then
+ Result := (LStartTime <= LTime) and (LTime <= LEndTime)
+ else
+ Result := (LStartTime < LTime) and (LTime < LEndTime);
+end;
+
+function DateInRange(ADate: TDate; AStartDate, AEndDate: TDate; AInclusive: Boolean = True): Boolean;
+begin
+ if AInclusive then
+ Result := (DateOf(AStartDate) <= DateOf(ADate)) and (DateOf(ADate) <= DateOf(AEndDate))
+ else
+ Result := (DateOf(AStartDate) < DateOf(ADate)) and (DateOf(ADate) < DateOf(AEndDate));
+end;
+
{ ---------------------------------------------------------------------
Period functions.
---------------------------------------------------------------------}
Mantis conversion info:
-
Mantis ID: 33598
-
Build: Any
-
Fixed in version: 3.1.1
-
Fixed in revision: 38767 (#c674f2c3)
-
Monitored by: » almuhandis (Renat Suleymanov)
-
Target version: 3.2.0