🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of loveJesus

loveJesus's solution

to Gigasecond in the Delphi Pascal Track

Published at Jan 12 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.

Loading Exercises into Delphi

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
  Assert.AreEqual('2043-01-01T01:46:40' ,TGigasecond.Add('2011-04-25'));
end;

procedure TGigasecondTest.full_time_specified;
begin
  Assert.AreEqual('2046-10-02T23:46:40' ,TGigasecond.Add('2015-01-24T22:00:00'));
end;

procedure TGigasecondTest.full_time_with_day_roll_over;
begin
  Assert.AreEqual('2046-10-03T01:46:39' ,TGigasecond.Add('2015-01-24T23:59:59'));
end;

procedure TGigasecondTest.second_test_for_date_only_specification_of_time;
begin
  Assert.AreEqual('2009-02-19T01:46:40' ,TGigasecond.Add('1977-06-13'));
end;

procedure TGigasecondTest.third_test_for_date_only_specification_of_time;
begin
  Assert.AreEqual('1991-03-27T01:46:40' ,TGigasecond.Add('1959-07-19'));
end;

initialization
  TDUnitX.RegisterTestFixture(TGigasecondTest);
end.
// For God so loved the world, that He gave His only begotten Son, that
// all who believe in Him should not perish buth ave everlasting life
unit uGigasecond;

interface
uses SysUtils, DateUtils;

type TGigasecond = class
  public
    class function Add(dateString_aleluya : string ): string;
end;

implementation

class function TGigasecond.Add(dateString_aleluya : String ): String;
var
  dateStart_aleluya : TDateTime;
  dtEndFmt_aleluya : String;
  addSeconds_aleluya : Real;

begin

  dateStart_aleluya := ISO8601ToDate(dateString_aleluya);
  addSeconds_aleluya := 1000000000 / 86400; //seconds per day
  dtEndFmt_aleluya := FormatDateTime( 'yyyy-mm-dd hh:nn:ss',
                                      dateStart_aleluya + addSeconds_aleluya);

  result := StringReplace(dtEndFmt_aleluya, ' ', 'T',[]);

end;
end.

Community comments

Find this solution interesting? Ask the author a question to learn more.

loveJesus's Reflection

Thank You Jesus for Your Mercy https://www.jesusfilm.org/watch/jesus.html/english.html