Skip to content

Commit

Permalink
Add GetTimeOrDefault method to TypedBucked
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed Nov 22, 2024
1 parent 6168e1c commit d5d52f1
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions boltz/typed_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,15 @@ func (bucket *TypedBucket) GetTimeOrError(name string) time.Time {
return *result
}

func (bucket *TypedBucket) GetTimeOrDefault(name string, defaultValue time.Time) time.Time {
fieldType, value := bucket.getTyped(name)
result := FieldToDatetime(fieldType, value, name)
if result == nil {
return defaultValue
}
return *result
}

func (bucket *TypedBucket) SetTime(name string, value time.Time, fieldChecker FieldChecker) *TypedBucket {
if bucket.ProceedWithSet(name, fieldChecker) {
if fieldBytes, err := value.UTC().MarshalBinary(); err == nil {
Expand Down

0 comments on commit d5d52f1

Please sign in to comment.