phizeroth's solution

to Gigasecond in the Crystal Track

Published at Jul 27 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.

Setup

Follow the setup instructions for Crystal here:

http://exercism.io/languages/crystal

More help installing can be found here:

http://crystal-lang.org/docs/installation/index.html

Making the Test Suite Pass

Execute the tests with:

``````\$ crystal spec
``````

In each test suite all but the first test have been skipped.

Once you get a test passing, you can unskip the next one by changing `pending` to `it`.

Source

Chapter 9 in Chris Pine's online Learn to Program tutorial. http://pine.fm/LearnToProgram/?Chapter=09

Submitting Incomplete Solutions

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

gigasecond_spec.cr

``````require "spec"
require "../src/*"

describe "Gigasecond" do
describe "#from" do
it "finds gigsecond from 2011_04_25" do
result = Gigasecond.from(Time.utc(2011, 4, 25, 0, 0, 0))
result.should eq Time.utc(2043, 1, 1, 1, 46, 40)
end

pending "finds gigsecond from 1977_06_13" do
result = Gigasecond.from(Time.utc(1977, 6, 13, 0, 0, 0))
result.should eq Time.utc(2009, 2, 19, 1, 46, 40)
end

pending "finds gigsecond from 1959_07_19" do
result = Gigasecond.from(Time.utc(1959, 7, 19, 0, 0, 0))
result.should eq Time.utc(1991, 3, 27, 1, 46, 40)
end

pending "finds gigsecond with full_time specified" do
result = Gigasecond.from(Time.utc(2015, 1, 24, 22, 0, 0))
result.should eq Time.utc(2046, 10, 2, 23, 46, 40)
end

pending "finds gigsecond with full_time with day rollover" do
result = Gigasecond.from(Time.utc(2015, 1, 24, 23, 59, 59))
result.should eq Time.utc(2046, 10, 3, 1, 46, 39)
end

pending "test_with_your_birthday" do
end
end
end``````
``````module Gigasecond
GIGA = 1e9

def self.from(time : Time)
time + GIGA.seconds
end
end``````
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}