Skip to content

Commit

Permalink
Merge pull request #19 from hookdeck/chore/NewDateTimeFromOptional
Browse files Browse the repository at this point in the history
chore: temp fix for NewDateTimeFromOptional helper
  • Loading branch information
leggetter authored Dec 11, 2024
2 parents c8dd166 + f1fd438 commit 7873145
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package api

import (
"time"

core "github.com/hookdeck/hookdeck-go-sdk/core"
)

Expand All @@ -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] {
Expand Down

0 comments on commit 7873145

Please sign in to comment.