type
TIBDate = Integer;
TIBTime = Longword;
TIBTimeStamp = packed record
Date: TIBDate;
Time: TIBTime;
end;
procedure IBDecodeDate(IBDate: TIBDate; var Year, Month, Day: SmallInt);
var
Century, Y, M, D: integer;
begin
IBDate := IBDate - (1721119 - 2400001);
Century := (4 * IBDate - 1) div 146097;
IBDate := 4 * IBDate - 1 - 146097 * Century;
D := IBDate div 4;
IBDate := (4 * D + 3) div 1461;
D := 4 * D + 3 - 1461 * IBDate;
D := (D + 4) div 4;
M := (5 * D - 3) div 153;
D := 5 * D - 3 - 153 * M;
D := (D + 5) div 5;
Y := 100 * Century + IBDate;
if M < 10 then
M := M + 3
else begin
M := M - 9;
Y := Y + 1;
end;
Year := Y;
Month := M;
Day := D;
end;
function IBEncodeDate(Year, Month, Day: SmallInt): TIBDate;
var
Century, ShortYear: integer;
begin
if Month > 2 then
Month := Month - 3
else begin
Month := Month + 9;
Year := Year - 1;
end;
Century := Year div 100;
ShortYear := Year - 100 * Century;
Result :=
(146097 * Century) div 4 +
(1461 * ShortYear) div 4 +
(153 * Month + 2) div 5 + Day + 1721119 - 2400001;
end;
procedure IBDecodeTime(IBTime: TIBTime; var Hour, Min, Sec, Msec: word);
const
ISC_TIME_SECONDS_PRECISION = 10000;
SECONDS_PER_MINUTE = 60;
SECONDS_PER_HOUR = 3600;
// SECONDS_PER_DAY = 86400;
var
TotalSeconds: Longword;
begin
TotalSeconds := IBTime div ISC_TIME_SECONDS_PRECISION;
Msec := IBTime mod ISC_TIME_SECONDS_PRECISION;
Hour := TotalSeconds div SECONDS_PER_HOUR;
Min := (TotalSeconds div SECONDS_PER_MINUTE) mod SECONDS_PER_MINUTE;
Sec := TotalSeconds mod SECONDS_PER_MINUTE;
end;
function IBEncodeTime(Hour, Min, Sec, Msec: word): TIBTime;
const
ISC_TIME_SECONDS_PRECISION = 10000;
SECONDS_PER_MINUTE = 60;
SECONDS_PER_HOUR = 3600;
// SECONDS_PER_DAY = 86400;
begin
Result := (Hour * SECONDS_PER_HOUR + Min * SECONDS_PER_MINUTE + Sec)
* ISC_TIME_SECONDS_PRECISION + Msec;
end;
TIBDate = Integer;
TIBTime = Longword;
TIBTimeStamp = packed record
Date: TIBDate;
Time: TIBTime;
end;
procedure IBDecodeDate(IBDate: TIBDate; var Year, Month, Day: SmallInt);
var
Century, Y, M, D: integer;
begin
IBDate := IBDate - (1721119 - 2400001);
Century := (4 * IBDate - 1) div 146097;
IBDate := 4 * IBDate - 1 - 146097 * Century;
D := IBDate div 4;
IBDate := (4 * D + 3) div 1461;
D := 4 * D + 3 - 1461 * IBDate;
D := (D + 4) div 4;
M := (5 * D - 3) div 153;
D := 5 * D - 3 - 153 * M;
D := (D + 5) div 5;
Y := 100 * Century + IBDate;
if M < 10 then
M := M + 3
else begin
M := M - 9;
Y := Y + 1;
end;
Year := Y;
Month := M;
Day := D;
end;
function IBEncodeDate(Year, Month, Day: SmallInt): TIBDate;
var
Century, ShortYear: integer;
begin
if Month > 2 then
Month := Month - 3
else begin
Month := Month + 9;
Year := Year - 1;
end;
Century := Year div 100;
ShortYear := Year - 100 * Century;
Result :=
(146097 * Century) div 4 +
(1461 * ShortYear) div 4 +
(153 * Month + 2) div 5 + Day + 1721119 - 2400001;
end;
procedure IBDecodeTime(IBTime: TIBTime; var Hour, Min, Sec, Msec: word);
const
ISC_TIME_SECONDS_PRECISION = 10000;
SECONDS_PER_MINUTE = 60;
SECONDS_PER_HOUR = 3600;
// SECONDS_PER_DAY = 86400;
var
TotalSeconds: Longword;
begin
TotalSeconds := IBTime div ISC_TIME_SECONDS_PRECISION;
Msec := IBTime mod ISC_TIME_SECONDS_PRECISION;
Hour := TotalSeconds div SECONDS_PER_HOUR;
Min := (TotalSeconds div SECONDS_PER_MINUTE) mod SECONDS_PER_MINUTE;
Sec := TotalSeconds mod SECONDS_PER_MINUTE;
end;
function IBEncodeTime(Hour, Min, Sec, Msec: word): TIBTime;
const
ISC_TIME_SECONDS_PRECISION = 10000;
SECONDS_PER_MINUTE = 60;
SECONDS_PER_HOUR = 3600;
// SECONDS_PER_DAY = 86400;
begin
Result := (Hour * SECONDS_PER_HOUR + Min * SECONDS_PER_MINUTE + Sec)
* ISC_TIME_SECONDS_PRECISION + Msec;
end;