home ~ projects ~ socials

Get A Location's Timezone From It's Latitude And Longitude In Rust

```cargo
[dependencies]
lazy_static = "1.5.0"
tzf-rs = "0.4.9"
```

use lazy_static::lazy_static;
use tzf_rs::DefaultFinder;

lazy_static! {
    static ref FINDER: DefaultFinder = DefaultFinder::new();
}

fn main() {
    print!("{:?}\n", FINDER.get_tz_name(-81.655647, 30.33));
    print!("{:?}\n", FINDER.get_tz_name(116.3883, 39.9289));
    print!("{:?}\n", FINDER.get_tz_names(116.3883, 39.9289));
}
Output:
"Asia/Shanghai"
["Asia/Shanghai"]
"America/New_York"

Notes

  • The values are backwards from how I normally see them (e.g. -81.655647, 30.33 instead of 30.33, -81.655647)
-- end of line --