Given a moment, determine the moment that would be after a gigasecond has passed.
A gigasecond is 10^9 (1,000,000,000) seconds.
Refer to the Installing Elm page for information about installing elm.
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:
To automatically run tests again when you save changes:
$ elm-test --watch
As you work your way through the tests suite in the file
be sure to remove the
calls from each test until you get them all passing!
Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09
It is possible to submit an incomplete solution so you can see how others have completed the exercise.
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") , skip <| test "1977-06-13" <| \() -> Expect.equal "2009-02-19T01:46:40.000Z" (gigasecond "1977-06-13") , skip <| test "1959-07-19" <| \() -> Expect.equal "1991-03-27T01:46:40.000Z" (gigasecond "1959-07-19") , skip <| test "full time specified" <| \() -> Expect.equal "2046-10-02T23:46:40.000Z" (gigasecond "2015-01-24T22:00:00.000Z") , skip <| 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 _ -> ""
module Gigasecond exposing (add) import Time add : Time.Posix -> Time.Posix add timestamp = let gigasecond = 10 ^ 9 in timestamp |> Time.posixToMillis |> (+) (gigasecond * 1000) |> Time.millisToPosix
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.