Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
}
19 changes: 19 additions & 0 deletions internal/exercises/templates/36_epoch/epoch_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package epoch

import "testing"

func TestEpochToTime(t *testing.T) {
got := EpochToTime(1633024800) // 2021-10-01 00:00:00 UTC
want := "2021-10-01 00:00:00"
if got != want {
t.Fatalf("EpochToTime(1633024800) = %q, want %q", got, want)
}
}

func TestTimeToEpoch(t *testing.T) {
got := TimeToEpoch("2021-10-01 00:00:00")
want := int64(1633024800)
if got != want {
t.Fatalf("TimeToEpoch(...) = %d, want %d", got, want)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
}