vkelman vkelman - 1 year ago 127
Node.js Question

Given local DateTime and lat/lon, how to determine a timezone and offset in NodeJs?

In the past I implemented C# library which, given local DateTime and lat/lon, allowed to determine a timezone and offset.
I did the following:

- downloaded shapefiles from efele.net/maps/tz,

- imported them into SQL Server,

- used them to get tzid from lat/lon,

Noda Time was used to get all necessary information about timezone, offset, and DST.
I returned:

- Offset in minutes,

- UTC DateTime,

- Olson/IANA Timezone name,

- Windows Timezone name,

- bool IsDST

Now I need to reproduce this library in NodeJs + PostgreSQL. Is the suggested way of doing it:

- Import efele.net/maps/tz shapefiles to PostgreSQL,

- Use Moment TimeZone library in NodeJs similar to how I used Noda Time in C#

Are there known pitfalls, difficulties?

Answer Source

As you said, you need some actualized shapefile to map all timezones by geo coordinates.

You can use a module like geo-tz that natively support moment-timezone library. Or a more lightweight one like tz-lookup.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download