Skip to content

Commit 027cd62

Browse files
authored
Merge pull request #5 from entropyx/date-translator
Date translator
2 parents 4bad007 + f3e9571 commit 027cd62

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

timeutils/date_translators.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package timeutils
2+
3+
import "time"
4+
5+
type MonthTranslator func(month time.Month) string
6+
7+
type WeekdayTranslator func(weekday time.Weekday) string

timeutils/english_translators.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package timeutils
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func MonthToEnglish(month time.Month) string {
9+
return fmt.Sprintf("%s", month)
10+
}
11+
12+
func WeekdayToEnglish(weekday time.Weekday) string {
13+
return fmt.Sprintf("%s", weekday)
14+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package timeutils
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
. "github.com/smartystreets/goconvey/convey"
8+
)
9+
10+
func TestMonthToEnglish(t *testing.T) {
11+
Convey("Given a time.Month", t, func() {
12+
month := time.Month(9)
13+
Convey("when calling MonthToEnglish", func() {
14+
stringMonth := MonthToEnglish(month)
15+
So(stringMonth, ShouldEqual, "September")
16+
})
17+
})
18+
}
19+
20+
func TestWeekdayToEnglish(t *testing.T) {
21+
Convey("Given a time.Weekday", t, func() {
22+
weekday := time.Weekday(1)
23+
Convey("when calling WeedayToEnglish", func() {
24+
stringWeekday := WeekdayToEnglish(weekday)
25+
So(stringWeekday, ShouldEqual, "Monday")
26+
})
27+
})
28+
}

timeutils/spanish_translators.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package timeutils
2+
3+
import "time"
4+
5+
var spanishMonth = map[time.Month]string{
6+
time.January: "Enero",
7+
time.February: "Febrero",
8+
time.March: "Marzo",
9+
time.April: "Abril",
10+
time.May: "Mayo",
11+
time.June: "Junio",
12+
time.July: "Julio",
13+
time.August: "Agosto",
14+
time.September: "Septiembre",
15+
time.October: "Octubre",
16+
time.November: "Noviembre",
17+
time.December: "Diciembre",
18+
}
19+
20+
func MonthToSpanish(month time.Month) string {
21+
return spanishMonth[month]
22+
}
23+
24+
var spanishWeekday = map[time.Weekday]string{
25+
time.Monday: "Lunes",
26+
time.Tuesday: "Martes",
27+
time.Wednesday: "Miércoles",
28+
time.Thursday: "Jueves",
29+
time.Friday: "Viernes",
30+
time.Saturday: "Sábado",
31+
time.Sunday: "Domingo",
32+
}
33+
34+
func WeekdayToSpanish(weekday time.Weekday) string {
35+
return spanishWeekday[weekday%7]
36+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package timeutils
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
. "github.com/smartystreets/goconvey/convey"
8+
)
9+
10+
func TestMonthToSpanish(t *testing.T) {
11+
Convey("Given a time.Month", t, func() {
12+
month := time.Month(11)
13+
Convey("when calling MonthToSpanish", func() {
14+
stringMonth := MonthToSpanish(month)
15+
So(stringMonth, ShouldEqual, "Noviembre")
16+
})
17+
})
18+
}
19+
20+
func TestWeekdayToSpanish(t *testing.T) {
21+
Convey("Given a time.Weekday", t, func() {
22+
weekday := time.Weekday(7)
23+
Convey("when calling WeekdayToSpanish", func() {
24+
stringWeekday := WeekdayToSpanish(weekday)
25+
So(stringWeekday, ShouldEqual, "Domingo")
26+
})
27+
})
28+
}

0 commit comments

Comments
 (0)