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
9 changes: 9 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@
"prerequisites": [],
"difficulty": 2,
"topics": []
},
{
"slug": "gigasecond",
"name": "Gigasecond",
"uuid": "505c9042-d830-4022-9830-2678586ba73a",
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": []
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/gigasecond/.docs/instructions.append.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raku is aware of leap seconds.
If the tests are seconds off then this may be a cause to work around.
5 changes: 5 additions & 0 deletions exercises/practice/gigasecond/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Instructions

Given a moment, determine the moment that would be after a gigasecond has passed.

A gigasecond is 10^9 (1,000,000,000) seconds.
17 changes: 17 additions & 0 deletions exercises/practice/gigasecond/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"authors": ["habere-et-dispertire"],
"files": {
"solution": [
"Gigasecond.rakumod"
],
"test": [
"gigasecond.rakutest"
],
"example": [
".meta/solutions/Gigasecond.rakumod"
]
},
"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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sub giga-later ( $date --> Str() ) is export {
DateTime.new( $date, formatter => {
sprintf "%04d-%02d-%02dT%02d:%02d:%02d", .year, .month, .day, .hour, .minute, .second }
)
.later: < seconds minutes hours days >
Z=> 10⁹.polymod: < 60 60 24 >
}
24 changes: 24 additions & 0 deletions exercises/practice/gigasecond/.meta/template-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
properties:
add:
test: |-
sprintf(q:to/END/, %case<input><moment>.raku, %case<expected>.raku, %case<description>.raku);
cmp-ok(
giga-later(%s),
"eqv",
%s,
%s,
);
END

example: |-
sub giga-later ( $date --> Str() ) is export {
DateTime.new( $date, formatter => {
sprintf "%04d-%02d-%02dT%02d:%02d:%02d", .year, .month, .day, .hour, .minute, .second }
)
.later: < seconds minutes hours days >
Z=> 10⁹.polymod: < 60 60 24 >
}

stub: |-
sub giga-later ($date) is export {
}
29 changes: 29 additions & 0 deletions exercises/practice/gigasecond/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[92fbe71c-ea52-4fac-bd77-be38023cacf7]
description = "date only specification of time"

[6d86dd16-6f7a-47be-9e58-bb9fb2ae1433]
description = "second test for date only specification of time"

[77eb8502-2bca-4d92-89d9-7b39ace28dd5]
description = "third test for date only specification of time"

[c9d89a7d-06f8-4e28-a305-64f1b2abc693]
description = "full time specified"

[09d4e30e-728a-4b52-9005-be44a58d9eba]
description = "full time with day roll-over"

[fcec307c-7529-49ab-b0fe-20309197618a]
description = "does not mutate the input"
include = false
2 changes: 2 additions & 0 deletions exercises/practice/gigasecond/Gigasecond.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sub giga-later ($date) is export {
}
41 changes: 41 additions & 0 deletions exercises/practice/gigasecond/gigasecond.rakutest
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env raku
use Test;
use lib $?FILE.IO.dirname;
use Gigasecond;

cmp-ok( # begin: 92fbe71c-ea52-4fac-bd77-be38023cacf7
giga-later("2011-04-25"),
"eqv",
"2043-01-01T01:46:40",
"date only specification of time",
); # end: 92fbe71c-ea52-4fac-bd77-be38023cacf7

cmp-ok( # begin: 6d86dd16-6f7a-47be-9e58-bb9fb2ae1433
giga-later("1977-06-13"),
"eqv",
"2009-02-19T01:46:40",
"second test for date only specification of time",
); # end: 6d86dd16-6f7a-47be-9e58-bb9fb2ae1433

cmp-ok( # begin: 77eb8502-2bca-4d92-89d9-7b39ace28dd5
giga-later("1959-07-19"),
"eqv",
"1991-03-27T01:46:40",
"third test for date only specification of time",
); # end: 77eb8502-2bca-4d92-89d9-7b39ace28dd5

cmp-ok( # begin: c9d89a7d-06f8-4e28-a305-64f1b2abc693
giga-later("2015-01-24T22:00:00"),
"eqv",
"2046-10-02T23:46:40",
"full time specified",
); # end: c9d89a7d-06f8-4e28-a305-64f1b2abc693

cmp-ok( # begin: 09d4e30e-728a-4b52-9005-be44a58d9eba
giga-later("2015-01-24T23:59:59"),
"eqv",
"2046-10-03T01:46:39",
"full time with day roll-over",
); # end: 09d4e30e-728a-4b52-9005-be44a58d9eba

done-testing;