Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
"math"
]
},
{
"slug" : "gigasecond",
"name" : "Gigasecond",
"uuid" : "acede85b-815e-4ebf-9bba-1fb945989021",
"practices" : [ ],
"prerequisites" : [ ],
"difficulty" : 1,
"topics" : [
"time"
]
},
{
"slug" : "hello-world",
"name" : "Hello World",
Expand Down
2 changes: 1 addition & 1 deletion dev/src/BaselineOfExercism/BaselineOfExercism.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BaselineOfExercism class >> exerciseGoldenTestPackageNames [
BaselineOfExercism class >> exercisePackageNames [
"Answer the list of exercise package names (as we don't yet have proper projects)"

^ #('Exercise@Acronym' 'Exercise@Allergies' 'Exercise@Anagram' 'Exercise@ArmstrongNumbers' 'Exercise@AtbashCipher' 'Exercise@Binary' 'Exercise@BinarySearchTree' 'Exercise@Bowling' 'Exercise@CircularBuffer' 'Exercise@Clock' 'Exercise@CollatzConjecture' 'Exercise@Darts' 'Exercise@Diamond' 'Exercise@Die' 'Exercise@Etl' 'Exercise@FlattenArray' 'Exercise@Forth' 'Exercise@GradeSchool' 'Exercise@Grains' 'Exercise@Hamming' 'Exercise@HelloWorld' 'Exercise@HighScores' 'Exercise@IsbnVerifier' 'Exercise@Isogram' 'Exercise@Leap' 'Exercise@Luhn' 'Exercise@MatchingBrackets' 'Exercise@Matrix' 'Exercise@Minesweeper' 'Exercise@OcrNumbers' 'Exercise@Pangram' 'Exercise@Proverb' 'Exercise@Raindrops' 'Exercise@ResistorColorDuo' 'Exercise@ReverseString' 'Exercise@RobotSimulator' 'Exercise@RomanNumerals' 'Exercise@SecretHandshake' 'Exercise@Sieve' 'Exercise@SimpleCipher' 'Exercise@SpaceAge' 'Exercise@SumOfMultiples' 'Exercise@Tournament' 'Exercise@TwelveDays' 'Exercise@TwoFer' 'Exercise@Welcome' 'Exercise@WordCount' 'Exercise@WordSearch')
^ #('Exercise@Acronym' 'Exercise@Allergies' 'Exercise@Anagram' 'Exercise@ArmstrongNumbers' 'Exercise@AtbashCipher' 'Exercise@Binary' 'Exercise@BinarySearchTree' 'Exercise@Bowling' 'Exercise@CircularBuffer' 'Exercise@Clock' 'Exercise@CollatzConjecture' 'Exercise@Darts' 'Exercise@Diamond' 'Exercise@Die' 'Exercise@Etl' 'Exercise@FlattenArray' 'Exercise@Forth' 'Exercise@Gigasecond' 'Exercise@GradeSchool' 'Exercise@Grains' 'Exercise@Hamming' 'Exercise@HelloWorld' 'Exercise@HighScores' 'Exercise@IsbnVerifier' 'Exercise@Isogram' 'Exercise@Leap' 'Exercise@Luhn' 'Exercise@MatchingBrackets' 'Exercise@Matrix' 'Exercise@Minesweeper' 'Exercise@OcrNumbers' 'Exercise@Pangram' 'Exercise@Proverb' 'Exercise@Raindrops' 'Exercise@ResistorColorDuo' 'Exercise@ReverseString' 'Exercise@RobotSimulator' 'Exercise@RomanNumerals' 'Exercise@SecretHandshake' 'Exercise@Sieve' 'Exercise@SimpleCipher' 'Exercise@SpaceAge' 'Exercise@SumOfMultiples' 'Exercise@Tournament' 'Exercise@TwelveDays' 'Exercise@TwoFer' 'Exercise@Welcome' 'Exercise@WordCount' 'Exercise@WordSearch')
]

{ #category : 'baselines' }
Expand Down
31 changes: 31 additions & 0 deletions dev/src/Exercise@Gigasecond/Gigasecond.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : 'Gigasecond',
#superclass : 'Object',
#category : 'Exercise@Gigasecond',
#package : 'Exercise@Gigasecond'
}

{ #category : 'accessing' }
Gigasecond class >> gigaSecond [

^ 1000000000 asSeconds
]

{ #category : 'adding' }
Gigasecond >> addMoment: aString [

^ String streamContents: [ :stream |
self
print: aString asDateAndTime + self class gigaSecond
asISODateAndTimeOn: stream
]
]

{ #category : 'printing' }
Gigasecond >> print: aDateAndTime asISODateAndTimeOn: stream [

stream
nextPutAll: aDateAndTime asDate yyyymmdd;
nextPut: $T;
nextPutAll: aDateAndTime asTime print24
]
141 changes: 141 additions & 0 deletions dev/src/Exercise@Gigasecond/GigasecondTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"
# Gigasecond

# Introduction

The way we measure time is kind of messy.
We have 60 seconds in a minute, and 60 minutes in an hour.
This comes from ancient Babylon, where they used 60 as the basis for their number system.
We have 24 hours in a day, 7 days in a week, and how many days in a month?
Well, for days in a month it depends not only on which month it is, but also on what type of calendar is used in the country you live in.

What if, instead, we only use seconds to express time intervals?
Then we can use metric system prefixes for writing large numbers of seconds in more easily comprehensible quantities.

- A food recipe might explain that you need to let the brownies cook in the oven for two kiloseconds (that's two thousand seconds).
- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds).
- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary.

~~~~exercism/note
If we ever colonize Mars or some other planet, measuring time is going to get even messier.
If someone says ""year"" do they mean a year on Earth or a year on Mars?

The idea for this exercise came from the science fiction novel [""A Deepness in the Sky""][vinge-novel] by author Vernor Vinge.
In it the author uses the metric system as the basis for time measurements.

[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/
~~~~

# Instructions

Your task is to determine the date and time one gigasecond after a certain date.

A gigasecond is one thousand million seconds.
That is a one with nine zeros after it.

If you were born on _January 24th, 2015 at 22:00 (10:00:00pm)_, then you would be a gigasecond old on _October 2nd, 2046 at 23:46:40 (11:46:40pm)_.

## Instructions append

The Kernel-Chronology package has many useful date and time related classes and protocols. The Date and Time class have useful printing methods which you can use to create your own ISO8601 date and time representation.


"
Class {
#name : 'GigasecondTest',
#superclass : 'ExercismTest',
#instVars : [
'gigasecond'
],
#category : 'Exercise@Gigasecond',
#package : 'Exercise@Gigasecond'
}

{ #category : 'config' }
GigasecondTest class >> exercise [

^ (ExercismExercise for: self)
difficulty: 1;
topics: #('time');
yourself
]

{ #category : 'config' }
GigasecondTest class >> exerciseTitle [
"Answer a title of this exercise"
^ 'Gigasecond'
]

{ #category : 'config' }
GigasecondTest class >> uuid [
"Answer a unique id for this exercise"
^'acede85b-815e-4ebf-9bba-1fb945989021'
]

{ #category : 'config' }
GigasecondTest class >> version [
"Generated from specification: 12 April 2025"
^'Not specified'
]

{ #category : 'running' }
GigasecondTest >> setUp [
super setUp.
gigasecond := Gigasecond new
]

{ #category : 'tests' }
GigasecondTest >> test01_DateOnlySpecificationOfTime [
"Tip: Remember to review the class [Comment] tab"
<exeTestName: 'date only specification of time'>
<exeTestUUID: '92fbe71c-ea52-4fac-bd77-be38023cacf7'>

| result |

result := gigasecond addMoment: '2011-04-25' .
self assert: result equals: '2043-01-01T01:46:40'
]

{ #category : 'tests' }
GigasecondTest >> test02_SecondTestForDateOnlySpecificationOfTime [
<exeTestName: 'second test for date only specification of time'>
<exeTestUUID: '6d86dd16-6f7a-47be-9e58-bb9fb2ae1433'>

| result |

result := gigasecond addMoment: '1977-06-13' .
self assert: result equals: '2009-02-19T01:46:40'
]

{ #category : 'tests' }
GigasecondTest >> test03_ThirdTestForDateOnlySpecificationOfTime [
<exeTestName: 'third test for date only specification of time'>
<exeTestUUID: '77eb8502-2bca-4d92-89d9-7b39ace28dd5'>

| result |

result := gigasecond addMoment: '1959-07-19' .
self assert: result equals: '1991-03-27T01:46:40'
]

{ #category : 'tests' }
GigasecondTest >> test04_FullTimeSpecified [
<exeTestName: 'full time specified'>
<exeTestUUID: 'c9d89a7d-06f8-4e28-a305-64f1b2abc693'>

| result |

result := gigasecond addMoment: '2015-01-24T22:00:00' .
self assert: result equals: '2046-10-02T23:46:40'
]

{ #category : 'tests' }
GigasecondTest >> test05_FullTimeWithDayRollover [
<exeTestName: 'full time with day roll-over'>
<exeTestUUID: '09d4e30e-728a-4b52-9005-be44a58d9eba'>

| result |

result := gigasecond addMoment: '2015-01-24T23:59:59' .
self assert: result equals: '2046-10-03T01:46:39'
]
1 change: 1 addition & 0 deletions dev/src/Exercise@Gigasecond/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'Exercise@Gigasecond' }
81 changes: 0 additions & 81 deletions dev/src/ExercismWIP/GigasecondTest.class.st

This file was deleted.

1 change: 1 addition & 0 deletions exercises/practice/gigasecond/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Kernel-Chronology package has many useful date and time related classes and protocols. The Date and Time class have useful printing methods which you can use to create your own ISO8601 date and time representation.
8 changes: 8 additions & 0 deletions exercises/practice/gigasecond/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Instructions

Your task is to determine the date and time one gigasecond after a certain date.

A gigasecond is one thousand million seconds.
That is a one with nine zeros after it.

If you were born on _January 24th, 2015 at 22:00 (10:00:00pm)_, then you would be a gigasecond old on _October 2nd, 2046 at 23:46:40 (11:46:40pm)_.
24 changes: 24 additions & 0 deletions exercises/practice/gigasecond/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Introduction

The way we measure time is kind of messy.
We have 60 seconds in a minute, and 60 minutes in an hour.
This comes from ancient Babylon, where they used 60 as the basis for their number system.
We have 24 hours in a day, 7 days in a week, and how many days in a month?
Well, for days in a month it depends not only on which month it is, but also on what type of calendar is used in the country you live in.

What if, instead, we only use seconds to express time intervals?
Then we can use metric system prefixes for writing large numbers of seconds in more easily comprehensible quantities.

- A food recipe might explain that you need to let the brownies cook in the oven for two kiloseconds (that's two thousand seconds).
- Perhaps you and your family would travel to somewhere exotic for two megaseconds (that's two million seconds).
- And if you and your spouse were married for _a thousand million_ seconds, you would celebrate your one gigasecond anniversary.

~~~~exercism/note
If we ever colonize Mars or some other planet, measuring time is going to get even messier.
If someone says "year" do they mean a year on Earth or a year on Mars?

The idea for this exercise came from the science fiction novel ["A Deepness in the Sky"][vinge-novel] by author Vernor Vinge.
In it the author uses the metric system as the basis for time measurements.

[vinge-novel]: https://www.tor.com/2017/08/03/science-fiction-with-something-for-everyone-a-deepness-in-the-sky-by-vernor-vinge/
~~~~
22 changes: 22 additions & 0 deletions exercises/practice/gigasecond/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"authors": [
"carlotxra"
],
"contributors": [
"Bajger"
],
"files": {
"solution": [
"Gigasecond.class.st"
],
"test": [
"GigasecondTest.class.st"
],
"example": [
".meta/solution/Gigasecond.class.st"
]
},
"blurb": "Given a moment, determine the moment that would be after a gigasecond has passed.",
"source": "Chapter 9 in Chris Pine's online Learn to Program tutorial.",
"source_url": "https://pine.fm/LearnToProgram/?Chapter=09"
}
31 changes: 31 additions & 0 deletions exercises/practice/gigasecond/.meta/solution/Gigasecond.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Class {
#name : 'Gigasecond',
#superclass : 'Object',
#category : 'Exercise@Gigasecond',
#package : 'Exercise@Gigasecond'
}

{ #category : 'accessing' }
Gigasecond class >> gigaSecond [

^ 1000000000 asSeconds
]

{ #category : 'adding' }
Gigasecond >> addMoment: aString [

^ String streamContents: [ :stream |
self
print: aString asDateAndTime + self class gigaSecond
asISODateAndTimeOn: stream
]
]

{ #category : 'printing' }
Gigasecond >> print: aDateAndTime asISODateAndTimeOn: stream [

stream
nextPutAll: aDateAndTime asDate yyyymmdd;
nextPut: $T;
nextPutAll: aDateAndTime asTime print24
]
Loading