Skip to content

Commit d8ae059

Browse files
Merge pull request #79 from IanWhitney/implement_gigasecond
Implement Gigasecond exercise
2 parents 0ba9109 + de70629 commit d8ae059

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"allergies",
1212
"word-count",
1313
"hamming",
14+
"gigasecond",
1415
"rna-transcription",
1516
"nucleotide-count",
1617
"nucleotide-codons",

exercises/gigasecond/Cargo.lock

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exercises/gigasecond/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "gigasecond"
3+
version = "0.0.0"
4+
5+
[dependencies]
6+
chrono = "0.2"
7+

exercises/gigasecond/example.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extern crate chrono;
2+
use chrono::*;
3+
4+
pub fn after(start: DateTime<UTC>) -> DateTime<UTC> {
5+
start + Duration::seconds(1_000_000_000)
6+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
extern crate gigasecond;
2+
3+
/*
4+
* Students,
5+
*
6+
* Rust does not currently have a library for handling Time. To solve this exercise
7+
* you'll need to use the Chrono 'crate' (which is Rust's term for an external library).
8+
*
9+
* The first time you run `cargo test`, the Chrono crate will automatically be downloaded
10+
* and installed. More information on crates can be found at
11+
* https://doc.rust-lang.org/book/guessing-game.html#generating-a-secret-number
12+
*
13+
* In order to use the crate, your solution will need to start with the two following lines
14+
*/
15+
extern crate chrono;
16+
use chrono::*;
17+
18+
#[test]
19+
fn test_date() {
20+
let start_date = UTC.ymd(2011, 4, 25).and_hms(0,0,0);
21+
assert_eq!(gigasecond::after(start_date), UTC.ymd(2043, 1, 1).and_hms(1,46,40));
22+
}
23+
24+
#[test]
25+
#[ignore]
26+
fn test_another_date() {
27+
let start_date = UTC.ymd(1977, 6, 13).and_hms(0,0,0);
28+
assert_eq!(gigasecond::after(start_date), UTC.ymd(2009, 2, 19).and_hms(1,46,40));
29+
}
30+
31+
#[test]
32+
#[ignore]
33+
fn test_third_date() {
34+
let start_date = UTC.ymd(1959, 7, 19).and_hms(0,0,0);
35+
assert_eq!(gigasecond::after(start_date), UTC.ymd(1991, 3, 27).and_hms(1,46,40));
36+
}
37+
38+
#[test]
39+
#[ignore]
40+
fn test_datetime() {
41+
let start_date = UTC.ymd(2015, 1, 24).and_hms(22,0,0);
42+
assert_eq!(gigasecond::after(start_date), UTC.ymd(2046, 10, 2).and_hms(23,46,40));
43+
}
44+
45+
#[test]
46+
#[ignore]
47+
fn test_another_datetime() {
48+
let start_date = UTC.ymd(2015, 1, 24).and_hms(23,59,59);
49+
assert_eq!(gigasecond::after(start_date), UTC.ymd(2046, 10, 3).and_hms(1,46,39));
50+
}

0 commit comments

Comments
 (0)