-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding gigasecond, not sure if it works
Signed-off-by: vsoch <vsochat@stanford.edu>
- Loading branch information
Showing
4 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Gigasecond | ||
|
||
Given a moment, determine the moment that would be after a gigasecond | ||
has passed. | ||
|
||
A gigasecond is 10^9 (1,000,000,000) seconds. | ||
|
||
## Elm Installation | ||
|
||
Refer to the [Installing Elm](https://exercism.io/tracks/elm/installation) page | ||
for information about installing elm. | ||
|
||
## Writing the Code | ||
|
||
The code you have to write is located inside the `src/` directory of the exercise. | ||
Elm automatically installs packages dependencies the first time you run the tests | ||
so we can start by running the tests from the exercise directory with: | ||
|
||
```bash | ||
$ elm-test | ||
``` | ||
|
||
To automatically run tests again when you save changes: | ||
|
||
```bash | ||
$ elm-test --watch | ||
``` | ||
|
||
As you work your way through the tests suite in the file `tests/Tests.elm`, | ||
be sure to remove the `skip <|` | ||
calls from each test until you get them all passing! | ||
|
||
## Source | ||
|
||
Chapter 9 in Chris Pine's online Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=09](http://pine.fm/LearnToProgram/?Chapter=09) | ||
|
||
## Submitting Incomplete Solutions | ||
|
||
It is possible to submit an incomplete solution so you can see how others have | ||
completed the exercise. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"type": "application", | ||
"source-directories": [ | ||
"src" | ||
], | ||
"elm-version": "0.19.1", | ||
"dependencies": { | ||
"direct": { | ||
"elm/browser": "1.0.0", | ||
"elm/core": "1.0.0", | ||
"elm/html": "1.0.0", | ||
"elm/parser": "1.1.0", | ||
"elm/regex": "1.0.0", | ||
"elm/time": "1.0.0", | ||
"justinmimbs/date": "3.2.1", | ||
"rtfeldman/elm-iso8601-date-strings": "1.1.2" | ||
}, | ||
"indirect": { | ||
"elm/json": "1.0.0", | ||
"elm/url": "1.0.0", | ||
"elm/virtual-dom": "1.0.0" | ||
} | ||
}, | ||
"test-dependencies": { | ||
"direct": { | ||
"elm-explorations/test": "1.0.0" | ||
}, | ||
"indirect": { | ||
"elm/random": "1.0.0" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Gigasecond exposing (add) | ||
|
||
import Time | ||
|
||
|
||
|
||
-- Add a gigasecond 10^9 (1,000,000,000) seconds | ||
|
||
|
||
add : Time.Posix -> Time.Posix | ||
add timestamp = | ||
Time.millisToPosix (Time.posixToMillis timestamp + gigasecond) | ||
|
||
|
||
gigasecond : Int | ||
gigasecond = | ||
10 ^ 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module Tests exposing (tests) | ||
|
||
import Expect | ||
import Gigasecond exposing (add) | ||
import Iso8601 | ||
import Parser | ||
import Test exposing (..) | ||
import Time | ||
|
||
|
||
tests : Test | ||
tests = | ||
describe "Gigasecond" | ||
[ describe "add" | ||
[ test "2011-04-25" <| | ||
\() -> | ||
Expect.equal "2043-01-01T01:46:40.000Z" | ||
(gigasecond "2011-04-25") | ||
, test "1977-06-13" <| | ||
\() -> | ||
Expect.equal "2009-02-19T01:46:40.000Z" | ||
(gigasecond "1977-06-13") | ||
, test "1959-07-19" <| | ||
\() -> | ||
Expect.equal "1991-03-27T01:46:40.000Z" | ||
(gigasecond "1959-07-19") | ||
, test "full time specified" <| | ||
\() -> | ||
Expect.equal "2046-10-02T23:46:40.000Z" | ||
(gigasecond "2015-01-24T22:00:00.000Z") | ||
, test "full time with day roll-over" <| | ||
\() -> | ||
Expect.equal "2046-10-03T01:46:39.000Z" | ||
(gigasecond "2015-01-24T23:59:59.000Z") | ||
] | ||
] | ||
|
||
|
||
gigasecond : String -> String | ||
gigasecond date = | ||
case Iso8601.toTime date of | ||
Ok posix -> | ||
posix | ||
|> Gigasecond.add | ||
|> Iso8601.fromTime | ||
|
||
_ -> | ||
"" |