Consequently, I came up with the following simple "addMinutes" function. This function takes a submitted time and a submitted number of minutes to add, and then returns the resulting time. If the new time is past midnight, it returns the time for the next day.
Here is the code:
Code: Select all
Vars: vOriginalMinutes(0), vOriginalHours(0);
Vars: vTempMinutes(0), vTempHours(0);
Vars: vNewMinutes(0), vNewHours(0);
vOriginalHours = IntPortion(RefTime/100);
vOriginalMinutes = Mod(RefTime,100);
vTestMinutes = vOriginalMinutes + RefMinutesToAdd;
If vTestMinutes <= 59 Then Begin
vNewMinutes = vTestMinutes;
vNewHours = vOriginalHours;
If vTestMinutes > 59 Then Begin
vTempMinutes = Mod(vTestMinutes,60);
vTempHours = IntPortion(vTestMinutes/60);
vNewMinutes = vTempMinutes;
If vNewMinutes > 59 Then Begin
vNewMinutes = vNewMinutes - 60;
vTempHours = vTempHours + 1;
vNewHours = vOriginalHours + vTempHours;
If vNewHours > 23 Then vNewHours = vNewHours - 24;
AddMinutes = (vNewHours * 100) + vNewMinutes;
When compiling this code, it should be saved as a function called "AddMinutes" with a return type of 'numeric' and a function storage of 'auto-detect''.
I've tested it on a limited basis and it seems to work fine. Maybe there is an easier way to do this but I don't know what it is. Feel free to play with it and let me know if you have any questions, ideas, bug reports or suggestions.