Exercism v3 launches on Sept 1st 2021. Learn more! ๐๐๐

brilang's solution

to Gigasecond in the CFML Track

Published at Oct 17 2018 · 0 comments
Instructions
Test suite
Solution

Calculate the moment when someone has lived for 10^9 seconds.

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
box task run TestRunner --:watcher
``````

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
* A gigasecond is 10^9 (1,000,000,000) seconds.
*/
component {

/**
* @returns
*/
function add( birthdate ) {
// return dateTimeFormat(dateAdd('s', 1000000000, birthdate), 'yyyy-mm-ddThh:nn:ss');
var outdate = dateAdd('s', 1000000000, birthdate);
return dateFormat(outdate, 'yyyy-mm-dd') & "T" & timeFormat(outdate, 'HH:mm:ss');
}

}``````

Community comments

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

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?
• Are there new concepts here that you could read more about to improve your understanding?