Skip to content

Commit 030db1c

Browse files
author
Ryan
committed
gigasecond
1 parent 7099b6b commit 030db1c

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

Diff for: gigasecond/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Gigasecond
2+
3+
Write a program that calculates the moment when someone has lived for 10^9 seconds.
4+
5+
A gigasecond is 10^9 (1,000,000,000) seconds.
6+
7+
## Setup
8+
9+
Go through the setup instructions for JavaScript to
10+
install the necessary dependencies:
11+
12+
http://exercism.io/languages/javascript
13+
14+
## Making the Test Suite Pass
15+
16+
Execute the tests with:
17+
18+
jasmine-node .
19+
20+
In many test suites all but the first test have been skipped.
21+
22+
Once you get a test passing, you can unskip the next one by
23+
changing `xit` to `it`.
24+
25+
## Source
26+
27+
Chapter 9 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=09](http://pine.fm/LearnToProgram/?Chapter=09)
28+
29+
## Submitting Incomplete Problems
30+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
31+

Diff for: gigasecond/gigasecond.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = class {
2+
constructor(date) {
3+
this.d = date
4+
}
5+
6+
date() {
7+
return new Date(this.d.getTime() + 10e11)
8+
}
9+
}

Diff for: gigasecond/gigasecond.spec.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
var Gigasecond = require('./gigasecond');
2+
3+
describe('Gigasecond', function() {
4+
5+
it('tells a gigasecond anniversary since midnight', function() {
6+
var gs = new Gigasecond(new Date(Date.UTC(2015, 8, 14)));
7+
var expectedDate = new Date(Date.UTC(2047, 4, 23, 1, 46, 40));
8+
expect(gs.date()).toEqual(expectedDate);
9+
});
10+
11+
it('tells the anniversary is next day when you are born at night', function() {
12+
var gs = new Gigasecond(new Date(Date.UTC(2015, 8, 14, 23, 59, 59)));
13+
var expectedDate = new Date(Date.UTC(2047, 4, 24, 1, 46, 39));
14+
expect(gs.date()).toEqual(expectedDate);
15+
});
16+
17+
it('even works before 1970 (beginning of Unix epoch)', function() {
18+
var gs = new Gigasecond(new Date(Date.UTC(1959, 6, 19, 5, 13, 45)));
19+
var expectedDate = new Date(Date.UTC(1991, 2, 27, 7, 0, 25));
20+
expect(gs.date()).toEqual(expectedDate);
21+
});
22+
23+
it('make sure calling "date" doesn\'t mutate value', function() {
24+
var gs = new Gigasecond(new Date(Date.UTC(1959, 6, 19, 5, 13, 45)));
25+
var expectedDate = new Date(Date.UTC(1991, 2, 27, 7, 0, 25));
26+
gs.date();
27+
expect(gs.date()).toEqual(expectedDate);
28+
});
29+
});

0 commit comments

Comments
 (0)