[fpc-devel] Patch for dateutil.inc how to apply?

Mark de Wever koraq at xs4all.nl
Tue Nov 15 19:53:24 CET 2005


Hello,

I'm new here and don't know what the way is to include a patch to the
system, so I decided to send it here.

Recently I needed to convert some Mac dates and wanted to use the Unix
conversion routines from the dateutils unit. Unfortunately they weren't
implanted yet. I wrote those routines along with the Mac ones I needed.
Attached the changes I made so they can be included in the rtl.

Regards,
Mark de Wever
-------------- next part --------------
--- dateutil.inc.orig	2005-11-15 19:38:58.923544296 +0100
+++ dateutil.inc	2005-11-15 19:36:49.243258696 +0100
@@ -397,6 +397,15 @@
 
 Function DateTimeToUnix(const AValue: TDateTime): Int64;
 Function UnixToDateTime(const AValue: Int64): TDateTime;
+Function UnixTimeStampToMac(const AValue: Int64): Int64;
+
+{ ---------------------------------------------------------------------
+    Mac timestamp support.
+  ---------------------------------------------------------------------}
+
+Function DateTimeToMac(const AValue: TDateTime): Int64;
+Function MacToDateTime(const AValue: Int64): TDateTime;
+Function MacTimeStampToUnix(const AValue: Int64): Int64;
 
 implementation
 
@@ -2006,15 +2015,58 @@
   ---------------------------------------------------------------------}
 
 Function DateTimeToUnix(const AValue: TDateTime): Int64;
+var
+  Epoch:TDateTime;
 begin
-  NotYetImplemented('DateTimeToUnix');
+  Epoch:=EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 );
+  Result:=SecondsBetween( Epoch, AValue );
 end;
 
 
 Function UnixToDateTime(const AValue: Int64): TDateTime;
+var
+  Epoch:TDateTime;
+begin
+  Epoch:=EncodeDateTime( 1970, 1, 1, 0, 0, 0, 0 );
+  Result:=IncSecond( Epoch, AValue );
+end;
+
+
+Function UnixTimeStampToMac(const AValue: Int64): Int64;
+const
+  Epoch=24107 * 24 * 3600;
+begin
+  Result:=AValue + Epoch;
+end;
+
+{ ---------------------------------------------------------------------
+    Mac timestamp support.
+  ---------------------------------------------------------------------}
+
+Function DateTimeToMac(const AValue: TDateTime): Int64;
+var
+  Epoch:TDateTime;
+begin
+  Epoch:=EncodeDateTime( 1904, 1, 1, 0, 0, 0, 0 );
+  Result:=SecondsBetween( Epoch, AValue );
+end;
+
 
+Function MacToDateTime(const AValue: Int64): TDateTime;
+var
+  Epoch:TDateTime;
 begin
-  NotYetImplemented('UnixToDateTime');
+  Epoch:=EncodeDateTime( 1904, 1, 1, 0, 0, 0, 0 );
+  Result:=IncSecond( Epoch, AValue );
 end;
 
+
+Function MacTimeStampToUnix(const AValue: Int64): Int64;
+const
+  Epoch=24107 * 24 * 3600; 
+begin
+  Result:=AValue - Epoch;
+end;
+
+
 end.


More information about the fpc-devel mailing list