# mk2s's solution

## to Gigasecond in the CFML Track

Published at Mar 06 2019 · 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.

To run the code in this exercise, you will only need to have CommandBox CLI installed. This binary runs CFML code from the command line.

To run the tests, `cd` into the exercise folder and run the following:

``````box task run TestRunner
# Or start up a test watcher that will rerun when files change
``````

The tests leverage a library called TestBox which supports xUnit and BDD style of testing. All test suites will be written in the BDD style which uses closures to define test specs. You won't need to worry about installing TestBox. The CLI test runner will take care of that for you. You just need to be connected to the internet the first time you run it. You can read more about it here:

https://testbox.ortusbooks.com/content/

## 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 can see how others have completed the exercise.

### GigasecondTest.cfc

``````component extends="testbox.system.BaseSpec" {

function beforeAll(){
SUT = createObject( 'Gigasecond' );
}

function run(){

describe( "My Gigasecond class", function(){

describe( 'Add one gigasecond to the input.', function(){

it( 'date only specification of time', function(){
expect( SUT.add( birthdate='2011-04-25' ) ).toBe( '2043-01-01T01:46:40' );
});

it( 'second test for date only specification of time', function(){
expect( SUT.add( birthdate='1977-06-13' ) ).toBe( '2009-02-19T01:46:40' );
});

it( 'third test for date only specification of time', function(){
expect( SUT.add( birthdate='1959-07-19' ) ).toBe( '1991-03-27T01:46:40' );
});

it( 'full time specified', function(){
expect( SUT.add( birthdate='2015-01-24T22:00:00' ) ).toBe( '2046-10-02T23:46:40' );
});

it( 'full time with day roll-over', function(){
expect( SUT.add( birthdate='2015-01-24T23:59:59' ) ).toBe( '2046-10-03T01:46:39' );
});

});

});

}

}``````

### SolutionTest.cfc

``````component extends="GigasecondTest" {

function beforeAll(){
SUT = createObject( 'Solution' );
}

}``````
``````/**
* Your implmentation of the Gigasecond exercise
*/
component {

/**
* @returns a date string like '2043-01-01T01:46:40'
* @arg birthdate is a date string like '2011-04-25' or '2043-01-01T01:46:40'
*/