Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

🕑 Batteries included 🔋, simple, fast time zone Lookup by GPS coordinates (lat/long) coordinates.

NotificationsYou must be signed in to change notification settings

catmullet/tz

Repository files navigation

Time Zone Lookup by Lat/Lon

Description

This is a library for timezone lookup by latitude and longitude. It uses a bounding box to check the most likely polygons with a more accurate winding number algorithm. We need both speed and highly accurate results and this is the resulting project.

Goals of this project?

  1. Speed
  2. Accuracy.
  3. Easy.
  4. Concurrent safe.
  5. Easy updating of zip file locally.

Simple

1. Grab the tz library.

    go get github.com/catmullet/tz

2. Update the geo json data fromevansiroky/timezone-boundary-builder*. (Likely not necessary.)

    make updategeo

*The script will delete the currenttzdata.snappycompiled TimeZone file and Download a new geojson zip file. This new geojson file will be loaded and compiled on the next run or by running unit tests. A newtzdata.snappy file will be created.

3. Copytzdata.snappy

Copy thetzdata.snappy file to the package you are going to initialize the time zone lookup object.

4. Initialize the GeoJson Time Zone Lookup.

lookup,err:=tz.NewGeoJsonTimeZoneLookup("timezones-with-oceans.geojson.zip")// OR// export GEO_JSON_FILE="path/timezones-with-oceans.geojson.zip" or will pull from root directorylookup,err:=tz.NewGeoJsonTimeZoneLookup("")// OR Get info from logginglookup,err:=tz.NewGeoJsonTimeZoneLookup("",os.Stderr)

5. Parse

Parse by Lat Lon and return string value of time zone.

timeZone:=lookup.TimeZone(5.261417,-3.925778)

Parse fortime.Location.

varti=time.Now()varloc,_=lookup.Location(5.261417,-3.925778)// Set time to location from lookup, easy!ti.In(loc).Zone()

Benchmarks

Tests performed with cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz

TestOperations Ranns per operation
BenchmarkTimeZone/coordinates_5.261417_-3.925778-12109633 op9837 ns/op
BenchmarkTimeZone/coordinates_-15.678889_34.973889-1241721 op27305 ns/op
BenchmarkTimeZone/coordinates_-12.65945_18.25674-1274956 op17318 ns/op
BenchmarkTimeZone/coordinates_41.8976_-87.6205-1259955 op19741 ns/op
BenchmarkTimeZone/coordinates_47.6897_-122.4023-1265709 op17656 ns/op
BenchmarkTimeZone/coordinates_42.7235_-73.6931-1298896 op12355 ns/op
BenchmarkTimeZone/coordinates_42.5807_-83.0223-1298629 op10762 ns/op
BenchmarkTimeZone/coordinates_36.8381_-84.85-1237291 op31924 ns/op
BenchmarkTimeZone/coordinates_40.1674_-85.3583-1257832 op19866 ns/op
BenchmarkTimeZone/coordinates_37.9643_-86.7453-1261338 op19274 ns/op
BenchmarkTimeZone/coordinates_38.6043_-90.2417-1261954 op20196 ns/op
BenchmarkTimeZone/coordinates_41.1591_-104.8261-1286883 op14256 ns/op
BenchmarkTimeZone/coordinates_35.1991_-111.6348-1261996 op18842 ns/op
BenchmarkTimeZone/coordinates_43.1432_-115.675-1250565 op24131 ns/op
BenchmarkTimeZone/coordinates_47.5886_-122.3382-1268821 op18421 ns/op
BenchmarkTimeZone/coordinates_58.3168_-134.4397-1293099 op13280 ns/op
BenchmarkTimeZone/coordinates_21.4381_-158.0493-1212163994 op96.95 ns/op
BenchmarkTimeZone/coordinates_42.7_-80-12135962 op8506 ns/op
BenchmarkTimeZone/coordinates_51.0036_-114.0161-12323289 op3779 ns/op
BenchmarkTimeZone/coordinates_-16.4965_-68.1702-1264844 op18756 ns/op
BenchmarkTimeZone/coordinates_-31.9369_115.8453-12275347 op4256 ns/op
BenchmarkTimeZone/coordinates_42_-87.5-1263606 op19925 ns/op
BenchmarkTimeZone/coordinates_41.8976_-87.6205#01-1263562 op19546 ns/op
BenchmarkTimeZone/coordinates_47.6897_-122.4023#01-1270030 op17950 ns/op
BenchmarkTimeZone/coordinates_42.7235_-73.6931#01-1296730 op12206 ns/op
BenchmarkTimeZone/coordinates_42.5807_-83.0223#01-12112562 op10770 ns/op
BenchmarkTimeZone/coordinates_36.8381_-84.85#01-1238658 op33090 ns/op
BenchmarkTimeZone/coordinates_40.1674_-85.3583#01-1258844 op20873 ns/op
BenchmarkTimeZone/coordinates_37.9643_-86.7453#01-1261153 op20413 ns/op
BenchmarkTimeZone/coordinates_38.6043_-90.2417#01-1250996 op21369 ns/op
BenchmarkTimeZone/coordinates_41.1591_-104.8261#01-1276140 op15558 ns/op
BenchmarkTimeZone/coordinates_35.1991_-111.6348#01-1260016 op19801 ns/op
BenchmarkTimeZone/coordinates_43.1432_-115.675#01-1246855 op25990 ns/op
BenchmarkTimeZone/coordinates_47.5886_-122.3382#01-1253744 op23905 ns/op
BenchmarkTimeZone/coordinates_58.3168_-134.4397#01-1266007 op16711 ns/op
BenchmarkTimeZone/coordinates_21.4381_-158.0493#01-128266512 op123.8 ns/op
BenchmarkTimeZone/coordinates_42.7_-80#01-12112492 op10378 ns/op
BenchmarkTimeZone/coordinates_51.0036_-114.0161#01-12294398 op4424 ns/op
BenchmarkTimeZone/coordinates_-16.4965_-68.1702#01-1260153 op19283 ns/op
BenchmarkTimeZone/coordinates_-31.9369_115.8453#01-12263713 op4694 ns/op
BenchmarkTimeZone/coordinates_42_-87.5#01-1261891 op20164 ns/op
BenchmarkTimeZone/coordinates_41.8976_-87.6205#02-1255926 op20487 ns/op
BenchmarkTimeZone/coordinates_47.6897_-122.4023#02-1267516 op19023 ns/op
BenchmarkTimeZone/coordinates_42.7235_-73.6931#02-1292011 op13674 ns/op
BenchmarkTimeZone/coordinates_42.5807_-83.0223#02-1297562 op12193 ns/op
BenchmarkTimeZone/coordinates_36.8381_-84.85#02-1236657 op32004 ns/op
BenchmarkTimeZone/coordinates_40.1674_-85.3583#02-1259169 op20827 ns/op
BenchmarkTimeZone/coordinates_37.9643_-86.7453#02-1259452 op20075 ns/op
BenchmarkTimeZone/coordinates_38.6043_-90.2417#02-1256371 op19961 ns/op
BenchmarkTimeZone/coordinates_41.1591_-104.8261#02-1279848 op14434 ns/op
BenchmarkTimeZone/coordinates_35.1991_-111.6348#02-1259436 op18598 ns/op
BenchmarkTimeZone/coordinates_43.1432_-115.675#02-1249734 op24137 ns/op
BenchmarkTimeZone/coordinates_47.5886_-122.3382#02-1266818 op18188 ns/op
BenchmarkTimeZone/coordinates_58.3168_-134.4397#02-1294588 op12781 ns/op
BenchmarkTimeZone/coordinates_21.4381_-158.0493#02-1212312768 op99.03 ns/op
BenchmarkTimeZone/coordinates_42.7_-80#02-12129206 op8987 ns/op
BenchmarkTimeZone/coordinates_51.0036_-114.0161#02-12310020 op4098 ns/op
BenchmarkTimeZone/coordinates_-16.4965_-68.1702#02-1261988 op21531 ns/op
BenchmarkTimeZone/coordinates_-31.9369_115.8453#02-12167610 op7179 ns/op
BenchmarkTimeZone/coordinates_42_-87.5#02-1251849 op20606 ns/op

About

🕑 Batteries included 🔋, simple, fast time zone Lookup by GPS coordinates (lat/long) coordinates.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp