The Mayor
2014-08-16 02:49:36
I have a question for you smart people out there. I want to know the shortest/best possible way to write this function.
The purpose of this function is to return the difference in time between the current system time, and another time I input. The time I input (myTime) will look like:
[hours, minutes, seconds, milliseconds]
I can return the current system time (timeNow) in the same format. I want to return the difference between these two times as a string (e.g., 2h 23m 2s 456ms).
For example:
myTime := [19, 30, 15, 0];
timeNow := [18, 30, 15, 0];
would return ‘1h 0m 0s 0ms’ (because 7:30 PM is one hour from the current time, 6:30 PM) and
myTime := [19, 30, 10, 0];
timeNow := [20, 25, 5, 0];
would return '23h 5m 5s 0ms' (Because 7:30:10 PM has already passed, the next time it will occur is 23 hours from now).
The purpose of this function is to return the difference in time between the current system time, and another time I input. The time I input (myTime) will look like:
[hours, minutes, seconds, milliseconds]
I can return the current system time (timeNow) in the same format. I want to return the difference between these two times as a string (e.g., 2h 23m 2s 456ms).
For example:
myTime := [19, 30, 15, 0];
timeNow := [18, 30, 15, 0];
would return ‘1h 0m 0s 0ms’ (because 7:30 PM is one hour from the current time, 6:30 PM) and
myTime := [19, 30, 10, 0];
timeNow := [20, 25, 5, 0];
would return '23h 5m 5s 0ms' (Because 7:30:10 PM has already passed, the next time it will occur is 23 hours from now).
function getTime(): array [0..3] of word;
begin
decodeTime(now(), result[0], result[1], result[2], result[3]);
end;
function differenceInTime(): string;
var
mytime, timeNow: array [0..3] of integer;
begin
myTime := [18, 30, 15, 0]; // [hour, min, sec, ms]
timeNow := getTime();
//halp
result := 'Xh ' + 'Xm ' + 'Xs ' + 'Xms';
end;