diff --git a/.fernignore b/.fernignore index bca19bd..27b0664 100644 --- a/.fernignore +++ b/.fernignore @@ -2,7 +2,7 @@ README.md LICENSE -# Temporarily ignored for the OptionalOrNull helper. +# Temporarily ignored for the OptionalOrNull and NewDateTimeFromOptional helpers. optional.go optional_test.go diff --git a/optional.go b/optional.go index 274a13f..9e826e8 100644 --- a/optional.go +++ b/optional.go @@ -3,6 +3,8 @@ package api import ( + "time" + core "github.com/hookdeck/hookdeck-go-sdk/core" ) @@ -13,6 +15,22 @@ func Optional[T any](value T) *core.Optional[T] { } } +// NewDateFromOptional returns a new *DateTime from the given optional. +func NewDateFromOptional(optional *core.Optional[time.Time]) *core.Date { + if optional == nil { + return nil + } + return core.NewDate(optional.Value) +} + +// NewDateTimeFromOptional returns a new *DateTime from the given optional. +func NewDateTimeFromOptional(optional *core.Optional[time.Time]) *core.DateTime { + if optional == nil { + return nil + } + return core.NewDateTime(optional.Value) +} + // Null initializes an optional field that will be sent as // an explicit null value. func Null[T any]() *core.Optional[T] {