# thekeele's solution

## to Gigasecond in the JavaScript Track

Published at Aug 18 2019 · 0 comments
Instructions
Test suite
Solution

#### Note:

This exercise has changed since this solution was written.

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

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

## Setup

Go through the setup instructions for Javascript to install the necessary dependencies:

https://exercism.io/tracks/javascript/installation

## Requirements

Install assignment dependencies:

\$ npm install

## Making the test suite pass

Execute the tests with:

\$ npm test

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by changing xtest to test.

## 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.

### gigasecond.spec.js

import { gigasecond } from './gigasecond';

describe('Gigasecond', () => {
test('tells a gigasecond anniversary since midnight', () => {
const gs = gigasecond(new Date(Date.UTC(2015, 8, 14)));
const expectedDate = new Date(Date.UTC(2047, 4, 23, 1, 46, 40));
expect(gs).toEqual(expectedDate);
});

xtest('tells the anniversary is next day when you are born at night', () => {
const gs = gigasecond(new Date(Date.UTC(2015, 8, 14, 23, 59, 59)));
const expectedDate = new Date(Date.UTC(2047, 4, 24, 1, 46, 39));
expect(gs).toEqual(expectedDate);
});

xtest('even works before 1970 (beginning of Unix epoch)', () => {
const gs = gigasecond(new Date(Date.UTC(1959, 6, 19, 5, 13, 45)));
const expectedDate = new Date(Date.UTC(1991, 2, 27, 7, 0, 25));
expect(gs).toEqual(expectedDate);
});
});
export const gigasecond = (time) => {
return new Date(time.setSeconds(time.getSeconds() + Math.pow(10, 9)));
};