Skip to content

ringsaturn/tzf-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

efbddee · Feb 15, 2025
Mar 11, 2024
Dec 1, 2024
Feb 15, 2025
Nov 11, 2024
Sep 2, 2023
Oct 16, 2022
Feb 15, 2025
May 30, 2022
Mar 17, 2024
Apr 2, 2024
Nov 11, 2024
Nov 11, 2024
Nov 11, 2024
Feb 15, 2025
Feb 15, 2025
Mar 17, 2024
Apr 2, 2024
Mar 17, 2024
Mar 17, 2024

Repository files navigation

Simple server convert longitude&latitude to timezone name

Note

It's designed as a debugger tool for package tzf, not production ready.

Quick Start

Install

Install via go install

go install github.com/ringsaturn/tzf-server@latest

Download from release page

Please visit https://github.com/ringsaturn/tzf-server/releases to get latest release.

Install from Docker Hub

docker pull ringsaturn/tzf-server

Usage

Usage of tzf-server:
  -disable-print-route
        Disable Print Route
  -hertz-prometheus-host-port string
        Hertz Prometheus Host&Port (default "0.0.0.0:8090")
  -hertz-prometheus-path string
        Hertz Prometheus Path (default "/hertz")
  -http-addr string
        HTTP Host&Port (default "0.0.0.0:8080")
  -path string
        custom data
  -prometheus-enable-go-coll
        Enable Go Collector (default true)
  -prometheus-host-port string
        Prometheus Host&Port (default "0.0.0.0:2112")
  -prometheus-path string
        Prometheus Path (default "/metrics")
  -redis-addr string
        Redis Server Host&Port (default "localhost:6380")
  -type int
        which finder to use Polygon(0) or Fuzzy(1)

For example, start DefaultFinder server:

tzf-server

Or start FuzzyFinder based server:

tzf-server -type 1

Web Pages

Note

Please note that the live demo below is runned on a free plan of Render, so it may take a while to start the server. Please do not use it for production.

All supported timezone names

[Experiment] Clickable debugger

I have little knowledge about frontend development so it's just a experiment, most codes are written by ChatGPT 3.5. You can access the prompts from gist.

HTTP API

Note

Please note that the live demo below is runned on a free plan of Render, so it may take a while to start the server. Please do not use it for production.

A swagger UI can be found at http://localhost:8080/swagger/index.html.

Or live demo: https://tzf-server.ringsaturn.me/swagger/index.html

Lookup Location's timezone

curl "http://localhost:8080/api/v1/tz?longitude=116.3883&latitude=39.9289"

or live demo:

curl "https://tzf-server.ringsaturn.me/api/v1/tz?longitude=116.3883&latitude=39.9289"

Output:

{
  "timezone": "Asia/Shanghai",
  "abbreviation": "CST",
  "offset": "28800s"
}

Lookup Location's timezones

curl "http://localhost:8080/api/v1/tzs?longitude=87.6168&latitude=43.8254"

or live demo:

curl "https://tzf-server.ringsaturn.me/api/v1/tzs?longitude=87.6168&latitude=43.8254"

Output:

{
  "timezones": [
    {
      "timezone": "Asia/Shanghai",
      "abbreviation": "CST",
      "offset": "28800s"
    },
    {
      "timezone": "Asia/Urumqi",
      "abbreviation": "+06",
      "offset": "21600s"
    }
  ]
}

All supported timezone names

curl "http://localhost:8080/api/v1/tzs/all"

or live demo:

curl "https://tzf-server.ringsaturn.me/api/v1/tzs/all"

Output:

{
  "timezones": [
    {
      "timezone": "Africa/Abidjan",
      "abbreviation": "GMT",
      "offset": "0s"
    },
    // ...
    {
      "timezone": "Etc/GMT+12",
      "abbreviation": "-12",
      "offset": "-43200s"
    }
  ]
}

Redis Protocol Commands

redis-cli

$ redis-cli -p 6380
127.0.0.1:6380> GET_TZ 116.3883 39.9289
Asia/Shanghai
127.0.0.1:6380> GET_TZS 87.4160 44.0400
1) "Asia/Shanghai"
2) "Asia/Urumqi"

redis-py

>>> from redis import Redis
>>> rc = Redis.from_url("redis://localhost:6380")
>>> rc.ping()
True
>>> rc.execute_command("get_tz", 116.3883, 39.9289).decode()
'Asia/Shanghai'
>>> rc.execute_command("get_tzs", 87.4160, 44.0400)
[b'Asia/Shanghai', b'Asia/Urumqi']