Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 8 additions & 0 deletions internal/exercises/catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,11 @@ projects:
hints:
- Implement an in-memory key-value store with basic CRUD operations and optional persistence.

- slug: 36_epoch
title: "Epoch Conversion"
difficulty: beginner
topics: ["time", "epoch", "unix"]
hints:
- "Use Go's `time.Unix()` to convert an epoch to time."
- "Use `t.Unix()` to convert time back to epoch."
- "Remember Go’s `time.Parse` can help parse date strings."
15 changes: 15 additions & 0 deletions internal/exercises/templates/36_epoch/epoch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package epoch

// TODO: Implement these functions so tests pass

// EpochToTime converts a unix epoch (seconds) into a formatted time string "2006-01-02 15:04:05".
func EpochToTime(epoch int64) string {
// Intentionally wrong to simulate failing exercise
return ""
}

// TimeToEpoch converts a formatted time string "2006-01-02 15:04:05" into a unix epoch (seconds).
func TimeToEpoch(input string) int64 {
// Intentionally wrong to simulate failing exercise
return 0
}
20 changes: 20 additions & 0 deletions internal/exercises/templates/36_epoch/epoch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package epoch

import "testing"

func TestEpochToTime(t *testing.T) {
const want = "2021-10-01 00:00:00"
const epoch = int64(1633046400) // 2021-10-01 00:00:00 UTC
got := EpochToTime(epoch)
if got != want {
t.Fatalf("EpochToTime(%d) = %q, want %q", epoch, got, want)
}
}
func TestTimeToEpoch(t *testing.T) {
const input = "2021-10-01 00:00:00"
const want = int64(1633046400)
got := TimeToEpoch(input)
if got != want {
t.Fatalf("TimeToEpoch(%q) = %d, want %d", input, got, want)
}
}