fixed issue with timezone and dst handling on openwrt platforms, thx !gm
This commit is contained in:
parent
e442504a6f
commit
1363655b59
1 changed files with 13 additions and 8 deletions
|
@ -25,6 +25,8 @@
|
|||
* along with sun. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _BSD_SOURCE 1 /* for tm_gmtoff field in struct tm */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
@ -32,7 +34,8 @@
|
|||
#include <getopt.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "../config.h"
|
||||
#include "sun.h"
|
||||
|
@ -120,7 +123,7 @@ int main(int argc, char *argv[]) {
|
|||
char *format = "%H:%M";
|
||||
char *query = NULL;
|
||||
bool error = false;
|
||||
int timezone = 0;
|
||||
int timezone = INT_MAX; /* magic value for system default with dst */
|
||||
|
||||
enum mode mode = INVALID;
|
||||
struct tm date;
|
||||
|
@ -131,12 +134,6 @@ int main(int argc, char *argv[]) {
|
|||
time(&t);
|
||||
localtime_r(&t, &date);
|
||||
|
||||
/* default timezone: system */
|
||||
struct timezone tz;
|
||||
if (gettimeofday(NULL, &tz) == 0) {
|
||||
timezone = -tz.tz_minuteswest / 60.0;
|
||||
}
|
||||
|
||||
/* parse mode */
|
||||
if (argc > 1 && argv[1][0] != '-') {
|
||||
if (strcmp(argv[1], "rise") == 0) mode = RISE;
|
||||
|
@ -179,6 +176,9 @@ int main(int argc, char *argv[]) {
|
|||
fprintf(stderr, "invalid date: %s\n", optarg);
|
||||
error = true;
|
||||
}
|
||||
else {
|
||||
mktime(&date); /* update date.tm_gmtoff */
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
|
@ -217,6 +217,10 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
if (timezone == INT_MAX) {
|
||||
timezone = date.tm_gmtoff / 3600;
|
||||
}
|
||||
|
||||
/* validate mode */
|
||||
if (mode == INVALID) {
|
||||
fprintf(stderr, "invalid mode\n");
|
||||
|
@ -268,6 +272,7 @@ int main(int argc, char *argv[]) {
|
|||
printf("calculate for: %s\n", date_str);
|
||||
printf("for position: %f, %f\n", pos.lat, pos.lon);
|
||||
printf("with twilight: %f\n", twilight);
|
||||
printf("with timezone: %d\n", timezone);
|
||||
#endif
|
||||
|
||||
/* start the calculation */
|
||||
|
|
Loading…
Add table
Reference in a new issue