Given a moment, determine the moment that would be after a gigasecond has passed.
A gigasecond is 10^9 (1,000,000,000) seconds.
Go through the setup instructions for Javascript to install the necessary dependencies:
https://exercism.io/tracks/javascript/installation
Install assignment dependencies:
$ npm install
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
.
Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
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);
});
});
const GIGASECOND = 10 ** 9;
export const gigasecond = moment =>
new Date(moment.getTime() + GIGASECOND * 1000);
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.
Level up your programming skills with 3,449 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors. Exercism is 100% free forever.
Sign up Learn More
Community comments