-
Notifications
You must be signed in to change notification settings - Fork 7
TTimeInterval
Ivan Semenkov edited this page Jan 28, 2021
·
1 revision
TTimeInterval is a class for working with time intervals. Class can convert it's stored value between microseconds and hours.
uses
utils.timeinterval;
type
TTimeInterval = class
type
TMicrosecond = class
TMillisecond = class
TSecond = class
TMinute = class
THour = class
end;
A new time interval class can be created by call its constructor.
constructor Create;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
FreeAndNil(interval);
end;
To get/set value for a TTimeInterval use next properties.
Get/set microseconds value.
property Microseconds : Int64;
property us : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
interval.Microseconds := 241;
writeln(interval.us);
FreeAndNil(interval);
end;
Get/set milliseconds value.
property Milliseconds : Int64;
property ms : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
interval.Milliseconds := 52;
writeln(interval.ms);
FreeAndNil(interval);
end;
Get/set seconds value.
property Seconds : Int64;
property s : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
interval.Seconds := 57;
writeln(interval.s);
FreeAndNil(interval);
end;
Get/set minutes value.
property Minutes : Int64;
property m : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
interval.Minutes := 29;
writeln(interval.m);
FreeAndNil(interval);
end;
Get/set hours value.
property Hours : Int64;
property h : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
interval.Hours := 14;
writeln(interval.h);
FreeAndNil(interval);
end;
To convert value use next properties.
Convert stored size to microseconds.
function ToMicroseconds : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
writeln(interval.ToMicroseconds);
FreeAndNil(interval);
end;
Convert stored size to milliseconds.
function ToMilliseconds : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
writeln(interval.ToMilliseconds);
FreeAndNil(interval);
end;
Convert stored size to seconds.
function ToSeconds : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
writeln(interval.ToSeconds);
FreeAndNil(interval);
end;
Convert stored size to minutes.
function ToMinutes : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
writeln(interval.ToMinutes);
FreeAndNil(interval);
end;
Convert stored size to hours.
function ToHours : Int64;
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
writeln(interval.ToHours);
FreeAndNil(interval);
end;
Format stored time interval to string value.
function ToString(ASuffix : string = '') : string;
ASuffix was append after value presentation.
uses
utils.timeinterval;
var
interval : TTimeInterval;
begin
interval := TTimeInterval.Create;
interval.Seconds := 9;
writeln(interval.ToString(' remaining')); { print '00:00:09 remaining' }
FreeAndNil(interval);
end;