program SecondsBreakdown;
type
TTimeBreakdown = record
Years : LongInt;
Months : LongInt;
Days : LongInt;
Hours : LongInt;
Minutes : LongInt;
Seconds : LongInt;
end;
{ Function using LongInt to handle up to ~2 billion seconds }
procedure ConvertSeconds(TotalSec: LongInt; var TB: TTimeBreakdown);
var
Remainder: LongInt;
begin
{ Idiomatic Pascal uses DIV for division and MOD for remainder }
TB.Years := TotalSec div 31536000; { 365 days }
Remainder := TotalSec mod 31536000;
TB.Months := Remainder div 2592000; { 30-day month approximation }
Remainder := Remainder mod 2592000;
TB.Days := Remainder div 86400;
Remainder := Remainder mod 86400;
TB.Hours := Remainder div 3600;
Remainder := Remainder mod 3600;
TB.Minutes := Remainder div 60;
TB.Seconds := Remainder mod 60;
end;
var
Input: LongInt;
Result: TTimeBreakdown;
begin
Input := 102300000;
ConvertSeconds(Input, Result);
WriteLn('Years: ', Result.Years);
WriteLn('Months: ', Result.Months);
WriteLn('Days: ', Result.Days);
WriteLn('Hours: ', Result.Hours);
WriteLn('Minutes: ', Result.Minutes);
WriteLn('Seconds: ', Result.Seconds);
end.
(*
run:
Years: 3
Months: 2
Days: 29
Hours: 0
Minutes: 40
Seconds: 0
*)