telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit 1b8b2051e841e7341f1af8ef8b6e3f131ab993db
parent 8e1c8befccd646067312bbcdd7cc9f286b586188
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri,  5 Oct 2018 09:38:40 +0200

Dynamically calculate timezone offset and add data to the payload

Diffstat:
Msrc/location.c | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/location.c b/src/location.c @@ -12,6 +12,7 @@ /* */ /*****************************************************************************/ +#include <time.h> #include <sys/socket.h> #include <kore/kore.h> @@ -55,6 +56,9 @@ location(struct http_request *req) MMDB_lookup_result_s lookup; MMDB_entry_data_s entry_data; + time_t rawtime; + struct tm *info; + http_populate_get(req); if (req->owner->addrtype == AF_INET) { @@ -116,6 +120,12 @@ location(struct http_request *req) MMDB_get_value(&lookup.entry, &entry_data, "location", "time_zone", NULL); if (entry_data.has_data) { json_object_set_new(output, "timezone", json_string(strndup(entry_data.utf8_string, entry_data.data_size))); + + setenv("TZ", strndup(entry_data.utf8_string, entry_data.data_size), 1); + tzset(); + time(&rawtime); + info = localtime(&rawtime); + json_object_set_new(output, "offset", json_integer(info->tm_gmtoff)); } json = json_dumps(output, JSON_INDENT(3));