Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint committed Jan 16, 2025
1 parent daf699e commit 8c00244
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sdk/go/examples/textgeneration/toolcalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func GenerateTextWithTools(prompt string) (string, error) {

// This function will return the current time in a given time zone.
func getCurrentTime(tz string) (string, error) {
if !localtime.IsValidTimeZone(tz) {
return "", errors.New("Invalid time zone.")
}

now, err := localtime.NowInZone(tz)
if err != nil {
return "", err
Expand Down
6 changes: 6 additions & 0 deletions sdk/go/pkg/localtime/localtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ func GetLocation(tz string) (*time.Location, error) {
}
return hostGetTimeLocation(tz)
}

// IsValidTimeZone returns true if the given time zone is valid.
func IsValidTimeZone(tz string) bool {
_, err := hostGetTimeInZone(tz)
return err == nil
}

0 comments on commit 8c00244

Please sign in to comment.