mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 21:49:11 +02:00
* pas2jni: Added TDateTime Java support class.
git-svn-id: trunk@32733 -
This commit is contained in:
parent
51a216f5ca
commit
f838251662
@ -67,6 +67,8 @@ type
|
|||||||
|
|
||||||
function DoCheckItem(const ItemName: string): TCheckItemResult;
|
function DoCheckItem(const ItemName: string): TCheckItemResult;
|
||||||
|
|
||||||
|
procedure WriteFileComment(st: TTextOutStream);
|
||||||
|
|
||||||
procedure ProcessRules(d: TDef; const Prefix: string = '');
|
procedure ProcessRules(d: TDef; const Prefix: string = '');
|
||||||
function GetUniqueNum: integer;
|
function GetUniqueNum: integer;
|
||||||
function DefToJniType(d: TDef; var err: boolean): string;
|
function DefToJniType(d: TDef; var err: boolean): string;
|
||||||
@ -299,6 +301,12 @@ begin
|
|||||||
Result:=crDefault;
|
Result:=crDefault;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TWriter.WriteFileComment(st: TTextOutStream);
|
||||||
|
begin
|
||||||
|
st.WriteLn('// This file was automatically generated by the pas2jni utility.');
|
||||||
|
st.WriteLn('// Do not edit this file.');
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TWriter.ProcessRules(d: TDef; const Prefix: string);
|
procedure TWriter.ProcessRules(d: TDef; const Prefix: string);
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
@ -1450,6 +1458,7 @@ begin
|
|||||||
u.Name:=LowerCase(u.Name);
|
u.Name:=LowerCase(u.Name);
|
||||||
Fjs:=TTextOutStream.Create(IncludeTrailingPathDelimiter(FPkgDir) + u.Name + '.java', fmCreate);
|
Fjs:=TTextOutStream.Create(IncludeTrailingPathDelimiter(FPkgDir) + u.Name + '.java', fmCreate);
|
||||||
try
|
try
|
||||||
|
WriteFileComment(Fjs);
|
||||||
Fjs.WriteLn(Format('package %s;', [JavaPackage]));
|
Fjs.WriteLn(Format('package %s;', [JavaPackage]));
|
||||||
HasSystem:=False;
|
HasSystem:=False;
|
||||||
if Length(u.UsedUnits) > 0 then begin
|
if Length(u.UsedUnits) > 0 then begin
|
||||||
@ -1463,6 +1472,11 @@ begin
|
|||||||
if not HasSystem then
|
if not HasSystem then
|
||||||
Fjs.WriteLn(Format('import %s.system.*;', [JavaPackage]));
|
Fjs.WriteLn(Format('import %s.system.*;', [JavaPackage]));
|
||||||
end;
|
end;
|
||||||
|
if u.Name = 'system' then begin
|
||||||
|
Fjs.WriteLn('import java.util.Date;');
|
||||||
|
Fjs.WriteLn('import java.util.TimeZone;');
|
||||||
|
end;
|
||||||
|
|
||||||
Fjs.WriteLn;
|
Fjs.WriteLn;
|
||||||
Fjs.WriteLn('public class ' + u.Name + ' {');
|
Fjs.WriteLn('public class ' + u.Name + ' {');
|
||||||
Fjs.IncI;
|
Fjs.IncI;
|
||||||
@ -1624,6 +1638,25 @@ begin
|
|||||||
Fjs.DecI;
|
Fjs.DecI;
|
||||||
Fjs.WriteLn('}');
|
Fjs.WriteLn('}');
|
||||||
Fjs.WriteLn;
|
Fjs.WriteLn;
|
||||||
|
|
||||||
|
// TDateTime support
|
||||||
|
Fjs.WriteLn('public static class TDateTime {');
|
||||||
|
Fjs.IncI;
|
||||||
|
Fjs.WriteLn('public static Date toDateUTC(double d) {');
|
||||||
|
Fjs.WriteLn('return new Date(Math.round((d - 25569)*86400000.0));', 1);
|
||||||
|
Fjs.WriteLn('}');
|
||||||
|
Fjs.WriteLn('public static Date toDate(double d) {');
|
||||||
|
Fjs.WriteLn('long t = Math.round((d - 25569)*86400000.0); return new Date(t - TimeZone.getDefault().getOffset(t));', 1);
|
||||||
|
Fjs.WriteLn('}');
|
||||||
|
Fjs.WriteLn('public static double getUTC(Date d) {');
|
||||||
|
Fjs.WriteLn('return d.getTime()/86400000.0 + 25569;', 1);
|
||||||
|
Fjs.WriteLn('}');
|
||||||
|
Fjs.WriteLn('public static double get(Date d) {');
|
||||||
|
Fjs.WriteLn('return (d.getTime() + TimeZone.getDefault().getOffset(d.getTime()))/86400000.0 + 25569;', 1);
|
||||||
|
Fjs.WriteLn('}');
|
||||||
|
Fjs.DecI;
|
||||||
|
Fjs.WriteLn('}');
|
||||||
|
Fjs.WriteLn;
|
||||||
end;
|
end;
|
||||||
Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage]));
|
Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage]));
|
||||||
Fjs.WriteLn;
|
Fjs.WriteLn;
|
||||||
@ -2304,8 +2337,7 @@ begin
|
|||||||
ForceDirectories(FPkgDir);
|
ForceDirectories(FPkgDir);
|
||||||
Fps:=TTextOutStream.Create(OutPath + LibName + '.pas', fmCreate);
|
Fps:=TTextOutStream.Create(OutPath + LibName + '.pas', fmCreate);
|
||||||
|
|
||||||
Fps.WriteLn('// This file was automatically generated by the pas2jni utility.');
|
WriteFileComment(Fps);
|
||||||
Fps.WriteLn('// Creation time: ' + DateTimeToStr(Now));
|
|
||||||
Fps.WriteLn('library '+ LibName + ';');
|
Fps.WriteLn('library '+ LibName + ';');
|
||||||
Fps.WriteLn('{$ifdef fpc} {$mode objfpc} {$H+} {$endif}');
|
Fps.WriteLn('{$ifdef fpc} {$mode objfpc} {$H+} {$endif}');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user