Skip to content

Commit

Permalink
Add jst variable
Browse files Browse the repository at this point in the history
  • Loading branch information
osamingo committed Mar 18, 2022
1 parent e0e94d9 commit 4dd05a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ type (
var (
// nolint: gochecknoglobals
nullLiteral = []byte("null")
// nolint: gochecknoglobals, gomnd
jst = time.FixedZone("Asia/Tokyo", int(9*time.Hour))

_ json.Unmarshaler = (*Version)(nil)
_ json.Unmarshaler = (*NullString)(nil)
Expand Down Expand Up @@ -204,7 +206,7 @@ func (h *Holiday) UnmarshalJSON(data []byte) error {
}

var err error
if h.Time, err = time.Parse(RFC3339DateFormat, tmp.Date); err != nil {
if h.Time, err = time.ParseInLocation(RFC3339DateFormat, tmp.Date, jst); err != nil {
return fmt.Errorf("kenall: failed to parse Holiday: %w", err)
}

Expand Down
2 changes: 1 addition & 1 deletion types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestHoliday_UnmarshalJSON(t *testing.T) {
wantTime time.Time
wantError bool
}{
"Normal case": {give: `{"title":"元日","date":"2022-01-01","day_of_week":6,"day_of_week_text":"saturday"}`, wantTitle: "元日", wantTime: time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC), wantError: false},
"Normal case": {give: `{"title":"元日","date":"2022-01-01","day_of_week":6,"day_of_week_text":"saturday"}`, wantTitle: "元日", wantTime: time.Date(2022, 1, 1, 0, 0, 0, 0, time.FixedZone("Asia/Tokyo", int(9*time.Hour))), wantError: false},
"Unexpected JSON value": {give: `{"title":2,"date":"2022-01-01","day_of_week":6,"day_of_week_text":"saturday"}`, wantTitle: "", wantTime: time.Time{}, wantError: true},
"Unexpected date format": {give: `{"title":"元日","date":"2022/01/01","day_of_week":6,"day_of_week_text":"saturday"}`, wantTitle: "", wantTime: time.Time{}, wantError: true},
}
Expand Down

0 comments on commit 4dd05a6

Please sign in to comment.