# paulfioravanti's solution

## to Gigasecond in the Elm Track

Published at Jun 19 2019 · 0 comments
Instructions
Test suite
Solution

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 page for information about installing elm.

## Writing the Code

The first time you start an exercise, you'll need to ensure you have the appropriate dependencies installed. Thankfully, Elm makes that easy for you and will install dependencies when you try to run tests or build the code.

Execute the tests with:

``````\$ elm-test
``````

Automatically run tests again when you save changes:

``````\$ elm-test --watch
``````

As you work your way through the test suite, 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

## Submitting Incomplete Solutions

It is possible to submit an incomplete solution so you can see how others have completed the exercise.

### Tests.elm

``````module Tests exposing (tests)

import Expect
import Iso8601
import Parser
import Test exposing (..)
import Time

tests : Test
tests =
describe "Gigasecond"
[ 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
|> Iso8601.fromTime

_ ->
""``````
``````module Gigasecond exposing (add)

import Time

let
milliSeconds =
10 ^ 12
in
timestamp
|> Time.posixToMillis
|> (+) milliSeconds
|> Time.millisToPosix``````