/* See LICENSE file for copyright and license details. */ #include "common.h" int libgeome_get_from_time(struct libgeome_context *ctx, struct libgeome_data *out) { time_t utc, local, uoff; struct tm tm; utc = time(NULL); if (utc < 0) { ctx->print_error(ctx, "time: %s\n", strerror(errno)); return -1; } if (!localtime_r(&utc, &tm)) { ctx->print_error(ctx, "localtime_r: %s\n", strerror(errno)); return -1; } local = (time_t)(tm.tm_hour * 60 * 60); local += (time_t)(tm.tm_min * 60); local += (time_t)tm.tm_sec; utc %= (time_t)(24 * 60 * 60); uoff = local - utc; out->requested_data &= LIBGEOME_DATUM_LONGITUDE; if (out->requested_data) { out->longitude = (double)uoff / (24 * 60 * 60 / 360); out->longitude = fmod(out->longitude, 360); if (out->longitude < -180) out->longitude += 360; else if (out->longitude > 180) out->longitude -= 360; } return 0; }