Sha256: 14d42271d7c3c90f253ffaaea87d70af61b0b47d49018e0ad2f708b0b7e950d3
Contents?: true
Size: 1.24 KB
Versions: 112
Compression:
Stored size: 1.24 KB
Contents
unit uClock; interface type Clock = Record strict private class function fltMod(x, y: double): integer; static; private hours: integer; minutes: integer; public constructor SetHands(aHours: integer; aMinutes: integer=0); function Add(minutesToAdd: integer): Clock; function Subtract(minutesToSubtract: integer): Clock; function ToString: string; End; implementation uses SysUtils, math; constructor Clock.SetHands(aHours: Integer; aMinutes: Integer = 0); begin hours := fltMod((aHours * 60 + aMinutes) / 60.0, 24); minutes := fltMod(aMinutes, 60); end; function Clock.Add(minutesToAdd: Integer): Clock; begin result := Clock.SetHands(hours, minutes + minutesToAdd); end; function Clock.Subtract(minutesToSubtract: Integer): Clock; begin result := Clock.SetHands(hours, minutes - minutesToSubtract); end; function Clock.ToString: string; begin result := format('%.2d:%.2d',[hours, minutes]); end; class function Clock.fltMod(x, y: double): integer; var intX, intY: integer; tmpFloat: double; xDy: double; begin intX := trunc(x); tmpFloat := x - intX; intY := trunc(y); result := trunc((intX mod intY) + tmpFloat + intY) mod intY; //Work around for lack of floating point MOD capability end; end.
Version data entries
112 entries across 112 versions & 1 rubygems