View Issue Details

IDProjectCategoryView StatusLast Update
0033598FPCRTLpublic2018-04-14 11:03
ReporterEnrique FuentesAssigned ToMichael Van Canneyt 
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Product VersionProduct BuildAny 
Target Version3.2.0Fixed in Version3.1.1 
Summary0033598: dateutil.inc implement new functions
DescriptionIndex: 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.
   ---------------------------------------------------------------------}
TagsNo tags attached.
Fixed in Revision38767
FPCOldBugId
FPCTarget
Attached Files

Activities

Marco van de Voort

2018-04-12 20:19

manager   ~0107759

(Inclusivity is a bit doubtful concept for floating point numbers)

Michael Van Canneyt

2018-04-14 11:03

administrator   ~0107772

Checked and appplied.

Thanks for the patch !

Issue History

Date Modified Username Field Change
2018-04-11 15:02 Enrique Fuentes New Issue
2018-04-11 15:21 Michael Van Canneyt Assigned To => Michael Van Canneyt
2018-04-11 15:21 Michael Van Canneyt Status new => assigned
2018-04-12 20:19 Marco van de Voort Note Added: 0107759
2018-04-14 11:03 Michael Van Canneyt Fixed in Revision => 38767
2018-04-14 11:03 Michael Van Canneyt Note Added: 0107772
2018-04-14 11:03 Michael Van Canneyt Status assigned => resolved
2018-04-14 11:03 Michael Van Canneyt Fixed in Version => 3.1.1
2018-04-14 11:03 Michael Van Canneyt Resolution open => fixed
2018-04-14 11:03 Michael Van Canneyt Target Version => 3.2.0