ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

Camgou's solution

to Gigasecond in the Delphi Pascal Track

Published at Mar 16 2021 · 0 comments
Instructions
Test suite
Solution

Given a moment, determine the moment that would be after a gigasecond has passed.

A gigasecond is 10^9 (1,000,000,000) seconds.

Testing

In order to run the tests for this track, you will need to install DUnitX. Please see the installation instructions for more information.

If Delphi is properly installed, and `*.dpr` file types have been associated with Delphi, then double clicking the supplied `*.dpr` file will start Delphi and load the exercise/project. `control + F9` is the keyboard shortcut to compile the project or pressing `F9` will compile and run the project.

Alternatively you may opt to start Delphi and load your project via. the `File` drop down menu.

When Questions Come Up

We monitor the Pascal-Delphi support room on gitter.im to help you with any questions that might arise.

Submitting Exercises

Note that, when trying to submit an exercise, make sure the exercise file you're submitting is in the `exercism/delphi/<exerciseName>` directory.

For example, if you're submitting `ubob.pas` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/delphi/bob/ubob.pas`.

Source

Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you may request help from a mentor.

uGigasecondTests.pas

``````unit uGigasecondTests;

interface
uses
DUnitX.TestFramework;

const
CanonicalVersion = '2.0.0.1';

type
[TestFixture]
TGigasecondTest = class(TObject)
public
[Test]
//    [Ignore('Comment the "[Ignore]" statement to run the test')]
procedure date_only_specification_of_time;

[Test]
[Ignore]
procedure second_test_for_date_only_specification_of_time;

[Test]
[Ignore]
procedure third_test_for_date_only_specification_of_time;

[Test]
[Ignore]
procedure full_time_specified;

[Test]
[Ignore]
procedure full_time_with_day_roll_over;
end;

implementation
uses
uGigasecond;

procedure TGigasecondTest.date_only_specification_of_time;
begin
end;

procedure TGigasecondTest.full_time_specified;
begin
end;

procedure TGigasecondTest.full_time_with_day_roll_over;
begin
end;

procedure TGigasecondTest.second_test_for_date_only_specification_of_time;
begin
end;

procedure TGigasecondTest.third_test_for_date_only_specification_of_time;
begin
end;

initialization
TDUnitX.RegisterTestFixture(TGigasecondTest);
end.``````
``````unit uGigasecond;

interface

uses
SysUtils, DateUtils, Soap.XSBuiltIns;

type

TGigasecond = class(TObject)
public
private
end;

implementation

{ TGigasecond }

var
DateTime: TDateTime;
Date: TXSDateTime;
Sec: Int64;
begin
Date := TXSDateTime.Create;

DateTime := Date.AsDateTime;

Sec := DateTimeToUnix(DateTime, False);
Sec := Sec + 1000000000;

DateTime := UnixToDateTime(Sec);

Result := FormatDateTime('yyyy"-"mm"-"dd"T"hh":"mm":"ss', DateTime);
end;

end.``````

What can you learn from this solution?

A huge amount can be learned from reading other peopleâ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

• What compromises have been made?