I know this sounds like your homework, but it's interesting to me, so I make a few comments.

Here's one way to do it. Once you have the time broken down into HOUR and MINUTE, call this routine to do the adjustment. It can only adjust for an interval of 0 to 60 minutes.

Your specifications seem confusing. If the interval is 30, do you want 10:30, 11:00, 11:30? or only 10:30, 11:30?

This routine performs "multiples" if the interval is less than 31, and forces the interval past the hour otherwise.

If you don't want the multiples, you can take it out, or add a parameter that specifies when to do it.

procedure AdjustToInterval(aUp:boolean; aIntMins:integer; var aHour,aMin:integer);

var

Diff:integer;

begin

{ Adjust hour/min to the next interval }

{ Intervals of 0 minutes or less and 61 or more are treated as 60 minutes }

{ Intervals 30 minutes or less are forced to a multiple of aIntMins }

{ Intervals 31 or more, are forced to aIntMins past the hour }

if (aIntMins<=0) or (60<aIntMins) then

aIntMins:=60;

if aIntMins>30 then begin

aIntMins:=aIntMins mod 60;

if aMin>=aIntMins then begin

{Force to next/prev hour}

aMin:=aIntMins;

if aUp then

inc(aHour)

else

dec(aHour);

end

else begin

{Force to current/prev hour}

aMin:=aIntMins;

if not aUp then

dec(aHour);

end;

end

else begin

{Interval less than 31 minutes}

{ How far from interval are the minutes? }

Diff:=aMin mod aIntMins;

if Diff=0 then begin

Diff:=aIntMins; {we go a complete interval}

end

else begin

{ Going to "next" interval }

if aUp then

Diff:=aIntMins-Diff; {subtract for up}

end;

if aUp then begin

aMin:=aMin+Diff;

end

else {down} begin

aMin:=aMin-Diff;

end;

end;

{ Sanity checks }

while aMin>=60 do begin

dec(aMin,60);

inc(aHour);

if aHour>=24 then

aHour:=aHour-24;

end;

while aMin<0 do begin

inc(aMin,60);

dec(aHour);

if aHour<0 then

aHour:=aHour+24;

end;

end;

Here's one way to do it. Once you have the time broken down into HOUR and MINUTE, call this routine to do the adjustment. It can only adjust for an interval of 0 to 60 minutes.

Your specifications seem confusing. If the interval is 30, do you want 10:30, 11:00, 11:30? or only 10:30, 11:30?

This routine performs "multiples" if the interval is less than 31, and forces the interval past the hour otherwise.

If you don't want the multiples, you can take it out, or add a parameter that specifies when to do it.

procedure AdjustToInterval(aUp:boole

var

Diff:integer;

begin

{ Adjust hour/min to the next interval }

{ Intervals of 0 minutes or less and 61 or more are treated as 60 minutes }

{ Intervals 30 minutes or less are forced to a multiple of aIntMins }

{ Intervals 31 or more, are forced to aIntMins past the hour }

if (aIntMins<=0) or (60<aIntMins) then

aIntMins:=60;

if aIntMins>30 then begin

aIntMins:=aIntMins mod 60;

if aMin>=aIntMins then begin

{Force to next/prev hour}

aMin:=aIntMins;

if aUp then

inc(aHour)

else

dec(aHour);

end

else begin

{Force to current/prev hour}

aMin:=aIntMins;

if not aUp then

dec(aHour);

end;

end

else begin

{Interval less than 31 minutes}

{ How far from interval are the minutes? }

Diff:=aMin mod aIntMins;

if Diff=0 then begin

Diff:=aIntMins; {we go a complete interval}

end

else begin

{ Going to "next" interval }

if aUp then

Diff:=aIntMins-Diff; {subtract for up}

end;

if aUp then begin

aMin:=aMin+Diff;

end

else {down} begin

aMin:=aMin-Diff;

end;

end;

{ Sanity checks }

while aMin>=60 do begin

dec(aMin,60);

inc(aHour);

if aHour>=24 then

aHour:=aHour-24;

end;

while aMin<0 do begin

inc(aMin,60);

dec(aHour);

if aHour<0 then

aHour:=aHour+24;

end;

end;