Sha256: e1f829b541bb485b024eea32c833f595b15c3a612a9f5e4cee531288ccfbfe3c

Contents?: true

Size: 1.21 KB

Versions: 156

Compression:

Stored size: 1.21 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 ToString: string;
    function Equal(aClock: Clock): Boolean;
  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.ToString: string;
begin
  result := format('%.2d:%.2d',[hours, minutes]);
end;

function Clock.Equal(aClock: Clock): Boolean;
begin
  result := (aClock.hours = hours) and (aClock.minutes = 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

156 entries across 156 versions & 1 rubygems

Version Path
trackler-2.2.1.100 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.99 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.98 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.97 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.96 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.95 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.94 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.93 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.92 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.91 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.90 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.89 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.88 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.87 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.86 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.85 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.84 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.83 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.82 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.2.1.81 tracks/delphi/exercises/clock/uClockExample.pas