Browse Source

* EncodeTimeInterval implemented, allowing time intervals>24 hour

git-svn-id: trunk@17410 -
joost 14 years ago
parent
commit
99bbb6e5cf
1 changed files with 24 additions and 0 deletions
  1. 24 0
      rtl/objpas/dateutil.inc

+ 24 - 0
rtl/objpas/dateutil.inc

@@ -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.
   ---------------------------------------------------------------------}
   ---------------------------------------------------------------------}
@@ -1692,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.