0

I'm using the weatherlib library in my code to find the sunrise and sunset time, but I can't find the user's current timezone for a latitude and longitude offline. Here's some extra information on the topic:

Reference forcalc_sunrise:

calc_sunrise (date, latitude, longitude, timezone)
Calculate the time of sunrise at the given date and location. Routines from the JavaScript code at http://www.esrl.noaa.gov/gmd/grad/solcalc/.
Parameters
- date: an os.date table representing the date for which to calculate the time of sunrise
- latitude: Latitude of the location
- longitude: Longitude of the location
- timezone: Timezone as an offset in hours from UTC at the given location
Return value:
- os.date table that holds the date and time when sunrise occurs

They also have a calc_timezone_offset function, but you need the string for the current timezone. Here's the reference for it:

calc_timezone_offset (timezone)
Calculate timezone offset from UTC in seconds for the given timezone. Uses external command date(1). Takes Daylight Saving Time into account if the local date command supports that. Tested only on Ubuntu Linux 10.04 and Solaris 10 operating systems. May not be very portable.
Parameters
- timezone: Timezone name, e.g. Europe/Helsinki, Asia/Bangkok, US/Pacific
Usage
- weatherlib.calc_timezone_offset('Europe/Helsinki') -- 7200
- weatherlib.calc_timezone_offset('Asia/Bangkok') -- 28800
- weatherlib.calc_timezone_offset('US/Pacific') -- -28800
Return value:
- Timezone offset in seconds from UTC. Positive for timezones ahead of UTC, negative for timezones behind UTC.

Thank you!
P.S. I did look for duplicate questions, but none gave me a answer for offline usage.

Edit: Specified I need this to be offline.

Zoyt
  • 4,809
  • 6
  • 33
  • 45
  • The sticking point will probably be finding a source that gives the exact boundaries of each timezone. Then you might be able to do something clever like sorting by latitude zones, rather than a fully generalized test for whether a given longitude/latitude lies within an arbitrary polygon. – Jim Lewis Dec 07 '13 at 00:59
  • @JimLewis - Thank you. Do you know if there is any place I can find the boundary position of time zones? Almost anything I Google links back to this question. – Zoyt Dec 07 '13 at 02:52
  • @JohnZwinck - Ah, I forgot I'm looking for this to be offline. I'm adding that to the question. – Zoyt Dec 07 '13 at 04:34
  • @MattJohnson - Same as above (I don't have permission to put more than one name in one comment) – Zoyt Dec 07 '13 at 04:35
  • @Zoyt - some of the options in the link I posted will work offline. – Matt Johnson-Pint Dec 07 '13 at 17:28

1 Answers1

0

I had missed the offline section in @MattJohnson's post. I got my data from whereonearth-timezone. Thank you!

Zoyt
  • 4,809
  • 6
  • 33
  • 45
  • You should also account for the use of daylight savings time and realize that both timezone and daylight savings time rules change over time. (This is one reason that Java libraries are updated several times per year.) – Tom Blodget Dec 08 '13 at 00:35