-
Notifications
You must be signed in to change notification settings - Fork 0
/
uPSR_dateutils.pas
63 lines (52 loc) · 1.76 KB
/
uPSR_dateutils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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.