Skip to content

Commit

Permalink
Merge pull request #13 from goark/debug-and-refactoring
Browse files Browse the repository at this point in the history
Move koyomi.DateJp to koyomi/value.DateJp
  • Loading branch information
spiegel-im-spiegel committed Feb 25, 2023
2 parents e3f2835 + 35bddb5 commit b2b12f5
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 90 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ^1.19
- uses: actions/checkout@v3
go-version-file: 'go.mod'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
Expand All @@ -44,3 +44,7 @@ jobs:
# skip-build-cache: true
- name: testing
run: go test -shuffle on ./...
- name: install govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: running govulncheck
run: govulncheck ./...
2 changes: 1 addition & 1 deletion .github/workflows/vulns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: ^1.19
go-version-file: 'go.mod'
- name: install depm
run: go install github.com/goark/depm@latest
- name: WriteGoList
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const (
## 簡単な使い方

```go
start, _ := koyomi.DateFrom("2019-05-01")
end := koyomi.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, koyomi.JST))
start, _ := value.DateFrom("2019-05-01")
end := value.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, koyomi.JST))
k, err := koyomi.NewSource(
koyomi.WithCalendarID(koyomi.Holiday, koyomi.SolarTerm),
koyomi.WithStartDate(start),
Expand Down Expand Up @@ -83,7 +83,7 @@ import (
"strconv"
"time"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
)

func main() {
Expand All @@ -106,7 +106,7 @@ func main() {
}
tm = time.Date(args[0], time.Month(args[1]), args[2], 0, 0, 0, 0, time.Local)
}
te := koyomi.NewDate(tm)
te := value.NewDate(tm)
n, y := te.YearEraString()
if len(n) == 0 {
fmt.Fprintln(os.Stderr, "正しい年月日を指定してください")
Expand Down Expand Up @@ -141,7 +141,7 @@ import (
"strconv"
"time"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
)

func main() {
Expand All @@ -162,7 +162,7 @@ func main() {
}
args[i] = num
}
te := koyomi.NewDateEra(koyomi.EraName(name), args[0], time.Month(args[1]), args[2], 0, 0, 0, 0, time.Local)
te := value.NewDateEra(value.EraName(name), args[0], time.Month(args[1]), args[2])
fmt.Println(te.Format("西暦2006年1月2日"))
}
```
Expand Down Expand Up @@ -190,7 +190,7 @@ import (
"fmt"
"os"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
"github.com/goark/koyomi/zodiac"
)

Expand All @@ -202,7 +202,7 @@ func main() {
return
}
for _, s := range args {
t, err := koyomi.DateFrom(s)
t, err := value.DateFrom(s)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
Expand Down Expand Up @@ -236,8 +236,8 @@ import (
"fmt"
"os"

"github.com/goark/koyomi"
"github.com/goark/koyomi/jdn"
"github.com/goark/koyomi/value"
)

func main() {
Expand All @@ -248,7 +248,7 @@ func main() {
return
}
for _, s := range args {
t, err := koyomi.DateFrom(s)
t, err := value.DateFrom(s)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
Expand Down
9 changes: 6 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
tasks:
default:
cmds:
- task: clean
- task: prepare
- task: test
- task: nancy
- task: graph
Expand All @@ -13,7 +13,8 @@ tasks:
cmds:
- go mod verify
- go test -shuffle on ./...
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.50.1 golangci-lint run --enable gosec --timeout 3m0s ./...
- govulncheck ./...
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.51.2 golangci-lint run --enable gosec --timeout 3m0s ./...
sources:
- ./go.mod
- '**/*.go'
Expand All @@ -26,13 +27,15 @@ tasks:
- ./go.mod
- '**/*.go'

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

clean:
desc: Initialize module and build cache, and remake go.sum file.
cmds:
- rm -f ./go.sum
- go clean -cache
- go clean -modcache
- go mod tidy -v -go=1.19

graph:
desc: Make grapth of dependency modules.
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.
15 changes: 8 additions & 7 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,34 @@ import (
"strconv"

"github.com/goark/errs"
"github.com/goark/koyomi/value"
)

//Event is koyomi event data
// Event is koyomi event data
type Event struct {
Date DateJp
Date value.DateJp
Title string
}

//Koyomi is array of Event
// Koyomi is array of Event
type Koyomi struct {
events []Event
}

//newKoyomi createw Koyomi instance
// newKoyomi createw Koyomi instance
func newKoyomi() *Koyomi {
return &Koyomi{events: make([]Event, 0)}
}

//Events returns event array
// Events returns event array
func (k *Koyomi) Events() []Event {
if k == nil {
return []Event{}
}
return k.events
}

//SortByDate sorts event data by date
// SortByDate sorts event data by date
func (k *Koyomi) SortByDate() {
if k == nil || len(k.events) <= 1 {
return
Expand All @@ -44,7 +45,7 @@ func (k *Koyomi) SortByDate() {
})
}

//Add adds other Kyomoi instance
// Add adds other Kyomoi instance
func (k *Koyomi) Add(kk *Koyomi) {
if kk == nil {
return
Expand Down
7 changes: 4 additions & 3 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"time"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
)

func ExampleKoyomi() {
start, _ := koyomi.DateFrom("2019-05-01")
end := koyomi.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, koyomi.JST))
start, _ := value.DateFrom("2019-05-01")
end := value.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, value.JST))
k, err := koyomi.NewSource(
koyomi.WithCalendarID(koyomi.Holiday, koyomi.SolarTerm),
koyomi.WithStartDate(start),
Expand Down Expand Up @@ -43,7 +44,7 @@ func ExampleKoyomi() {
//"2019-05-21","小満"
}

/* Copyright 2020 Spiegel
/* Copyright 2020-2023 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
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.19
go 1.20

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

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/goark/errs v1.1.0 h1:FKnyw4LVyRADIjM8Nj0Up6r0/y5cfADvZAd1E+tthXE=
github.com/goark/errs v1.1.0/go.mod h1:TtaPEoadm2mzqzfXdkkfpN2xuniCFm2q4JH+c1qzaqw=
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/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=
Expand Down
7 changes: 4 additions & 3 deletions sample/sample0.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"time"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
)

func main() {
start, _ := koyomi.DateFrom("2019-05-01")
end := koyomi.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, koyomi.JST))
start, _ := value.DateFrom("2019-05-01")
end := value.NewDate(time.Date(2019, time.May, 31, 0, 0, 0, 0, value.JST))
k, err := koyomi.NewSource(
koyomi.WithCalendarID(koyomi.Holiday, koyomi.SolarTerm),
koyomi.WithStartDate(start),
Expand All @@ -31,7 +32,7 @@ func main() {
io.Copy(os.Stdout, bytes.NewReader(csv))
}

/* Copyright 2022 Spiegel
/* Copyright 2023 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
6 changes: 3 additions & 3 deletions sample/sample1.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"time"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
)

func main() {
Expand All @@ -33,7 +33,7 @@ func main() {
}
tm = time.Date(args[0], time.Month(args[1]), args[2], 0, 0, 0, 0, time.Local)
}
te := koyomi.NewDate(tm)
te := value.NewDate(tm)
n, y := te.YearEraString()
if len(n) == 0 {
fmt.Fprintln(os.Stderr, "正しい年月日を指定してください")
Expand All @@ -42,7 +42,7 @@ func main() {
fmt.Printf("%s%s%d月%d日\n", n, y, te.Month(), te.Day())
}

/* Copyright 2019-2022 Spiegel
/* Copyright 2019-2023 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
6 changes: 3 additions & 3 deletions sample/sample2.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strconv"
"time"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
)

func main() {
Expand All @@ -31,11 +31,11 @@ func main() {
}
args[i] = num
}
te := koyomi.NewDateEra(koyomi.EraName(name), args[0], time.Month(args[1]), args[2])
te := value.NewDateEra(value.EraName(name), args[0], time.Month(args[1]), args[2])
fmt.Println(te.Format("西暦2006年1月2日"))
}

/* Copyright 2019-2022 Spiegel
/* Copyright 2019-2023 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
4 changes: 2 additions & 2 deletions sample/sample3.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"
"os"

"github.com/goark/koyomi"
"github.com/goark/koyomi/value"
"github.com/goark/koyomi/zodiac"
)

Expand All @@ -20,7 +20,7 @@ func main() {
return
}
for _, s := range args {
t, err := koyomi.DateFrom(s)
t, err := value.DateFrom(s)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
Expand Down
4 changes: 2 additions & 2 deletions sample/sample4.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"fmt"
"os"

"github.com/goark/koyomi"
"github.com/goark/koyomi/jdn"
"github.com/goark/koyomi/value"
)

func main() {
Expand All @@ -20,7 +20,7 @@ func main() {
return
}
for _, s := range args {
t, err := koyomi.DateFrom(s)
t, err := value.DateFrom(s)
if err != nil {
fmt.Fprintln(os.Stderr, err)
continue
Expand Down
Loading

0 comments on commit b2b12f5

Please sign in to comment.