|
|
|
|
@ -13,6 +13,9 @@ typedef struct {
|
|
|
|
|
char *comments;
|
|
|
|
|
char *city;
|
|
|
|
|
char *country;
|
|
|
|
|
char *zone;
|
|
|
|
|
double lat;
|
|
|
|
|
double lon;
|
|
|
|
|
} yon_timezone_struct;
|
|
|
|
|
|
|
|
|
|
void _yon_timezone_countries_setup(GHashTable *timezone_countries){
|
|
|
|
|
@ -51,18 +54,37 @@ int yon_timezone_init(){
|
|
|
|
|
yon_timezone_struct *timezone_info = malloc(sizeof(yon_timezone_struct));
|
|
|
|
|
memset(timezone_info,0,sizeof(yon_timezone_struct));
|
|
|
|
|
|
|
|
|
|
char *city = strstr(parsed[2],"/");
|
|
|
|
|
if (yon_char_count(parsed[2],"/")>1){
|
|
|
|
|
timezone_info->timezone = yon_char_new(parsed[2]);
|
|
|
|
|
free(yon_char_divide_search(timezone_info->timezone,"/",-1));
|
|
|
|
|
} else {
|
|
|
|
|
timezone_info->timezone = yon_char_new(parsed[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *city = strstr(timezone_info->timezone,"/");
|
|
|
|
|
if (city){
|
|
|
|
|
city++;
|
|
|
|
|
}
|
|
|
|
|
char *zone = yon_char_new(timezone_info->timezone);
|
|
|
|
|
char *temp = strstr(zone,"/");
|
|
|
|
|
if (temp){
|
|
|
|
|
temp[0]='\0';
|
|
|
|
|
}
|
|
|
|
|
timezone_info->country_code = yon_char_new(parsed[0]);
|
|
|
|
|
timezone_info->timezone = yon_char_new(parsed[2]);
|
|
|
|
|
timezone_info->city = yon_char_new(city);
|
|
|
|
|
timezone_info->country = yon_char_new(g_hash_table_lookup(timezone_countries,parsed[0]));
|
|
|
|
|
timezone_info->zone = zone;
|
|
|
|
|
char *coords = yon_char_new(parsed[1]);
|
|
|
|
|
char *pos = strstr(coords+1,"+");
|
|
|
|
|
char *ngt = strstr(coords+1,"-");
|
|
|
|
|
char *lat = coords;
|
|
|
|
|
char *lon = !yon_char_is_empty(pos)?yon_char_new(pos):yon_char_new(ngt);
|
|
|
|
|
|
|
|
|
|
if (parsed_size>3){
|
|
|
|
|
timezone_info->comments = yon_char_new(parsed[3]);
|
|
|
|
|
}
|
|
|
|
|
g_hash_table_insert(__yon_timezone,yon_char_new(parsed[2]),timezone_info);
|
|
|
|
|
g_hash_table_insert(__yon_timezone,yon_char_new(timezone_info->timezone),timezone_info);
|
|
|
|
|
|
|
|
|
|
yon_char_parsed_free(parsed,parsed_size);
|
|
|
|
|
}
|
|
|
|
|
@ -131,6 +153,16 @@ char *yon_timezone_get_country(const char *timezone){
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *yon_timezone_get_zone(const char *timezone){
|
|
|
|
|
yon_timezone_check{
|
|
|
|
|
yon_timezone_struct *timezone_info = g_hash_table_lookup(__yon_timezone,timezone);
|
|
|
|
|
if (timezone_info){
|
|
|
|
|
return yon_char_new(timezone_info->zone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define get_utc_command(tz) yon_char_unite("TZ='",tz,"' date +%z",NULL);
|
|
|
|
|
|
|
|
|
|
char *yon_timezone_get_utc(const char *timezone){
|
|
|
|
|
@ -144,4 +176,21 @@ char *yon_timezone_get_utc(const char *timezone){
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
config_str yon_timezone_get_zones_from_region(char *region, size_t *size){
|
|
|
|
|
size_t timezones_size;
|
|
|
|
|
(*size) = 0;
|
|
|
|
|
yon_timezone_check{
|
|
|
|
|
config_str zones_final = NULL;
|
|
|
|
|
config_str timezones = (config_str)g_hash_table_get_keys_as_array(__yon_timezone,(guint*)&timezones_size);
|
|
|
|
|
for (size_t i=0;i<timezones_size;i++){
|
|
|
|
|
yon_timezone_struct *timezone_info = g_hash_table_lookup(__yon_timezone,timezones[i]);
|
|
|
|
|
if (timezone_info&&!yon_char_is_empty(timezone_info->zone)&&!strcmp(timezone_info->zone,region)){
|
|
|
|
|
yon_char_parsed_add_or_create_if_exists(zones_final,(int*)size,timezone_info->city);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
qsort(zones_final,*size,sizeof(char*),(__compar_fn_t)yon_char_parsed_compare);
|
|
|
|
|
return zones_final;
|
|
|
|
|
}
|
|
|
|
|
}
|