Skip to content

Go (tzf)

Reuse the Finder

Initializing a Finder, FuzzyFinder, or DefaultFinder is expensive — it loads and parses the timezone data file. Always reuse a single instance, for example as a package-level variable:

package main

import (
	"fmt"

	"github.com/ringsaturn/tzf"
)

var f tzf.F

func init() {
	var err error
	f, err = tzf.NewDefaultFinder()
	if err != nil {
		panic(err)
	}
}

func main() {
	fmt.Println(f.GetTimezoneName(116.3883, 39.9289))
	fmt.Println(f.GetTimezoneName(-73.935242, 40.730610))
}