ðŸŽ‰ Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io ðŸŽ‰

# epequeno's solution

## to Gigasecond in the Elm Track

Published at Apr 19 2021 · 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 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:

\$ elm-test

To automatically run tests again when you save changes:

\$ 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

## 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

_ ->
""

import Time

Time.posixToMillis timestamp
+ (10 ^ 9)
* 1000
|> Time.millisToPosix