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

Version Path
trackler-2.1.0.6 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.1.0.5 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.1.0.4 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.1.0.3 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.1.0.2 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.1.0.1 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.1.0.0 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.55 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.54 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.53 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.52 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.51 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.50 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.49 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.48 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.47 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.46 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.45 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.44 tracks/delphi/exercises/clock/uClockExample.pas
trackler-2.0.8.43 tracks/delphi/exercises/clock/uClockExample.pas