Skip to content

Commit

Permalink
supported civil date for period
Browse files Browse the repository at this point in the history
  • Loading branch information
Code-Hex committed Oct 1, 2023
1 parent 7f5865a commit 919cfb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion period.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type timeish[T TimeZone] interface {
Time[T] | time.Time | constraints.Bytes
Time[T] | time.Time | Date[T] | constraints.Bytes
}

var stringType = reflect.TypeOf("")
Expand Down Expand Up @@ -194,6 +194,8 @@ func convertTime[T TimeZone](arg any) (Time[T], error) {
return v, nil
case time.Time:
return In[T](v), nil
case Date[T]:
return v.Time(), nil
case string:
return ParseISO[T](v)
case []byte:
Expand Down
21 changes: 21 additions & 0 deletions period_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ func TestPeriod_Slice(t *testing.T) {
t.Fatalf("(-want, +got)\n%s", diff)
}
})
t.Run("Date[UTC] params", func(t *testing.T) {
period, err := NewPeriod[tz.UTC](
Date[tz.UTC]{
Year: 2014,
Month: 2,
Day: 5,
},
Date[tz.UTC]{
Year: 2014,
Month: 2,
Day: 8,
},
)
if err != nil {
t.Fatal(err)
}
got := period.PeriodicDuration(24 * time.Hour).Slice()
if diff := cmp.Diff(want, got); diff != "" {
t.Fatalf("(-want, +got)\n%s", diff)
}
})
t.Run("time.Time params", func(t *testing.T) {
period, err := NewPeriod[tz.UTC](
time.Date(2014, 2, 5, 0, 0, 0, 0, time.UTC),
Expand Down

0 comments on commit 919cfb0

Please sign in to comment.