1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-22 17:22:21 -05:00
Simba/Units/PascalScript/uPSR_dateutils.pas
Wizzup? 9d6c4ee850 eol-style: native
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@58 3f818213-9676-44b0-a9b4-5e4c4e03d09d
2009-09-13 19:47:09 +00:00

64 lines
1.8 KiB
ObjectPascal

unit uPSR_dateutils;
{$I PascalScript.inc}
interface
uses
SysUtils, uPSRuntime;
procedure RegisterDateTimeLibrary_R(S: TPSExec);
implementation
function TryEncodeDate(Year, Month, Day: Word; var Date: TDateTime): Boolean;
begin
try
Date := EncodeDate(Year, Month, Day);
Result := true;
except
Result := false;
end;
end;
function TryEncodeTime(Hour, Min, Sec, MSec: Word; var Time: TDateTime): Boolean;
begin
try
Time := EncodeTime(hour, Min, Sec, MSec);
Result := true;
except
Result := false;
end;
end;
function DateTimeToUnix(D: TDateTime): Int64;
begin
Result := Round((D - 25569) * 86400);
end;
function UnixToDateTime(U: Int64): TDateTime;
begin
Result := U / 86400 + 25569;
end;
procedure RegisterDateTimeLibrary_R(S: TPSExec);
begin
S.RegisterDelphiFunction(@EncodeDate, 'ENCODEDATE', cdRegister);
S.RegisterDelphiFunction(@EncodeTime, 'ENCODETIME', cdRegister);
S.RegisterDelphiFunction(@TryEncodeDate, 'TRYENCODEDATE', cdRegister);
S.RegisterDelphiFunction(@TryEncodeTime, 'TRYENCODETIME', cdRegister);
S.RegisterDelphiFunction(@DecodeDate, 'DECODEDATE', cdRegister);
S.RegisterDelphiFunction(@DecodeTime, 'DECODETIME', cdRegister);
S.RegisterDelphiFunction(@DayOfWeek, 'DAYOFWEEK', cdRegister);
S.RegisterDelphiFunction(@Date, 'DATE', cdRegister);
S.RegisterDelphiFunction(@Time, 'TIME', cdRegister);
S.RegisterDelphiFunction(@Now, 'NOW', cdRegister);
S.RegisterDelphiFunction(@DateTimeToUnix, 'DATETIMETOUNIX', cdRegister);
S.RegisterDelphiFunction(@UnixToDateTime, 'UNIXTODATETIME', cdRegister);
S.RegisterDelphiFunction(@DateToStr, 'DATETOSTR', cdRegister);
S.RegisterDelphiFunction(@FormatDateTime, 'FORMATDATETIME', cdRegister);
S.RegisterDelphiFunction(@StrToDate, 'STRTODATE', cdRegister);
end;
end.