radcheb / Adhan

High precision prayer time library
MIT License
13 stars 4 forks source link

timegm function only available on Linux #4

Closed Cyrillius closed 6 years ago

Cyrillius commented 7 years ago

@radcheb Be careful, the timegm function is only available on a linux OS. I can give you a time_t struct with the UTC time.

Cyrillius commented 7 years ago

same thing for tm_zone and tm_gmtoff;

I can give you the actual offset

void setToLocalTz(struct tm* date){
    time_t now = time(0);
    struct tm* local_date = localtime(&now);
    date->tm_zone = local_date->tm_zone;
    date->tm_isdst = local_date->tm_isdst;
    date->tm_gmtoff = local_date->tm_gmtoff;
}
radcheb commented 7 years ago

Is also gmtime (the inverse of timegm) only available in Linux OS ?

Cyrillius commented 7 years ago

Ok, Into the watch there is no operating system (OS) . Therefore the standard library doesn't know what is the current UTC time. I can give you in the function parameter a pointer to the actual UTC time.

radcheb commented 6 years ago

I replaced all timegm with localtime and gmtime with mktime. However, you need to set TZ to UTC in order to get correct results: 81ad812344abb52a9d732104c8d2ae80d0a1a0af