Skip to content

Commit

Permalink
Merge pull request #14 from goark/debug-and-refactoring
Browse files Browse the repository at this point in the history
Add DateJp.WeekdayJp and DateJp.WeekdayJpShort methods
  • Loading branch information
spiegel-im-spiegel committed Jun 2, 2024
2 parents b2b12f5 + a76b332 commit ed4ce86
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tasks:
- go mod verify
- go test -shuffle on ./...
- govulncheck ./...
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.51.2 golangci-lint run --enable gosec --timeout 3m0s ./...
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:latest golangci-lint run --enable gosec --timeout 3m0s ./...
sources:
- ./go.mod
- '**/*.go'
Expand All @@ -28,7 +28,7 @@ tasks:
- '**/*.go'

prepare:
- go mod tidy -v -go=1.20
- go mod tidy -v -go=1.22

clean:
desc: Initialize module and build cache, and remake go.sum file.
Expand Down
Binary file modified dependency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/goark/koyomi

go 1.20
go 1.22

require (
github.com/goark/errs v1.2.2
github.com/goark/errs v1.3.2
github.com/spiegel-im-spiegel/ics-golang v0.1.0
)

Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/goark/errs v1.2.2 h1:UrMZZJL0WaOzaO+ErSV+nz/k/+bmW2wUiFe5V7pUeEo=
github.com/goark/errs v1.2.2/go.mod h1:ZsQucxaDFVfSB8I99j4bxkDRfNOrlKINwg72QMuRWKw=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goark/errs v1.3.2 h1:ifccNe1aK7Xezt4XVYwHUqalmnfhuphnEvh3FshCReQ=
github.com/goark/errs v1.3.2/go.mod h1:ZsQucxaDFVfSB8I99j4bxkDRfNOrlKINwg72QMuRWKw=
github.com/goark/fetch v0.3.0 h1:2m32EGOLBi99RzI5urFfmv5++CMqfenVw7NH8z/lbX8=
github.com/goark/fetch v0.3.0/go.mod h1:sqDdPbbHeIjDVeHrgvzhHpkUr8X9pVC9DgJoVwU02x0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spiegel-im-spiegel/ics-golang v0.1.0 h1:B+HHGJa6MqeJq15lAe2hGo7dfnx6t4jq451Nqice4mY=
github.com/spiegel-im-spiegel/ics-golang v0.1.0/go.mod h1:TpSbav1X/sYTlZq2aNDU8NZg9c8HcuAG2GnNVUy1zA4=
github.com/spiegel-im-spiegel/iso8601duration v0.1.0 h1:AL8GyapnN1uGrFg/mvimc8xpOdVNU2XoaqL/WRDxe7s=
github.com/spiegel-im-spiegel/iso8601duration v0.1.0/go.mod h1:Fe92GUFYxNfo+IRNEeJNvZHqQeH1MAz1send1zriltg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 14 additions & 1 deletion value/date.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,20 @@ func (t DateJp) AddDay(days int) DateJp {
return t.AddDate(0, 0, days)
}

/* Copyright 2020-2023 Spiegel
var weekdayNames = [7]string{"日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"}
var weekdayShortNames = [7]string{"日", "月", "火", "水", "木", "金", "土"}

// WeekdayJp returns japanese weekday name.
func (t DateJp) WeekdayJp() string {
return weekdayNames[t.Weekday()%7]
}

// WeekdayJp returns japanese weekday short name.
func (t DateJp) WeekdayJpShort() string {
return weekdayShortNames[t.Weekday()%7]
}

/* Copyright 2020-2024 Spiegel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
33 changes: 32 additions & 1 deletion value/date_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,37 @@ type ForTestStruct struct {
DateTaken DateJp `json:"date_taken,omitempty"`
}

func TestWeekdayJp(t *testing.T) {
testCases := []struct {
s string
name string
short string
}{
{s: "2024-06-01T09:00:00+09:00", name: "土曜日", short: "土"},
{s: "2024-06-02T09:00:00+09:00", name: "日曜日", short: "日"},
{s: "2024-06-03T09:00:00+09:00", name: "月曜日", short: "月"},
{s: "2024-06-04T09:00:00+09:00", name: "火曜日", short: "火"},
{s: "2024-06-05T09:00:00+09:00", name: "水曜日", short: "水"},
{s: "2024-06-06T09:00:00+09:00", name: "木曜日", short: "木"},
{s: "2024-06-07T09:00:00+09:00", name: "金曜日", short: "金"},
}

for _, tc := range testCases {
dt, err := DateFrom(tc.s)
if err != nil {
t.Errorf("value.DateFrom() is \"%v\", want nil.", err)
continue
}
wd := dt.WeekdayJp()
if wd != tc.name {
t.Errorf("DateJp.WeekdayJp() is \"%v\", want \"%v\".", wd, tc.name)
}
wd = dt.WeekdayJpShort()
if wd != tc.short {
t.Errorf("DateJp.WeekdayJp() is \"%v\", want \"%v\".", wd, tc.short)
}
}
}
func TestUnmarshal(t *testing.T) {
testCases := []struct {
s string
Expand Down Expand Up @@ -78,7 +109,7 @@ func TestEqual(t *testing.T) {
}
}

/* Copyright 2020-2023 Spiegel
/* Copyright 2020-2024 Spiegel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit ed4ce86

Please sign in to comment.