* pas2jni: Added TDateTime Java support class.

git-svn-id: trunk@32733 -
This commit is contained in:
yury 2015-12-26 19:52:03 +00:00
parent 51a216f5ca
commit f838251662

View File

@ -67,6 +67,8 @@ type
function DoCheckItem(const ItemName: string): TCheckItemResult;
procedure WriteFileComment(st: TTextOutStream);
procedure ProcessRules(d: TDef; const Prefix: string = '');
function GetUniqueNum: integer;
function DefToJniType(d: TDef; var err: boolean): string;
@ -299,6 +301,12 @@ begin
Result:=crDefault;
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);
var
i: integer;
@ -1450,6 +1458,7 @@ begin
u.Name:=LowerCase(u.Name);
Fjs:=TTextOutStream.Create(IncludeTrailingPathDelimiter(FPkgDir) + u.Name + '.java', fmCreate);
try
WriteFileComment(Fjs);
Fjs.WriteLn(Format('package %s;', [JavaPackage]));
HasSystem:=False;
if Length(u.UsedUnits) > 0 then begin
@ -1463,6 +1472,11 @@ begin
if not HasSystem then
Fjs.WriteLn(Format('import %s.system.*;', [JavaPackage]));
end;
if u.Name = 'system' then begin
Fjs.WriteLn('import java.util.Date;');
Fjs.WriteLn('import java.util.TimeZone;');
end;
Fjs.WriteLn;
Fjs.WriteLn('public class ' + u.Name + ' {');
Fjs.IncI;
@ -1624,6 +1638,25 @@ begin
Fjs.DecI;
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;
Fjs.WriteLn(Format('static { %s.system.InitJni(); }', [JavaPackage]));
Fjs.WriteLn;
@ -2304,8 +2337,7 @@ begin
ForceDirectories(FPkgDir);
Fps:=TTextOutStream.Create(OutPath + LibName + '.pas', fmCreate);
Fps.WriteLn('// This file was automatically generated by the pas2jni utility.');
Fps.WriteLn('// Creation time: ' + DateTimeToStr(Now));
WriteFileComment(Fps);
Fps.WriteLn('library '+ LibName + ';');
Fps.WriteLn('{$ifdef fpc} {$mode objfpc} {$H+} {$endif}');