glong tz_location_get_utc_offset (TzLocation *loc) { TzInfo *tz_info; glong offset; tz_info = tz_info_from_location (loc); offset = tz_info->utc_offset; tz_info_free (tz_info); return offset; }
static void set_location (CcTimezoneMap *map, TzLocation *location) { CcTimezoneMapPrivate *priv = map->priv; TzInfo *info; priv->location = location; info = tz_info_from_location (priv->location); priv->selected_offset = tz_location_get_utc_offset (priv->location) / (60.0*60.0) + ((info->daylight) ? -1.0 : 0.0); g_signal_emit (map, signals[LOCATION_CHANGED], 0, priv->location); tz_info_free (info); }
// ----------------------------------------------------------------------------- bool tzn::got(long tm_gmtoff, TzLocation& locret, TzInfo& nforet) { DEBUGLOGB; int fnd = 0; bool ret = false; DEBUGLOGP("requested entry gmt offset is %d\n", (int)tm_gmtoff); GPtrArray* locs = tz_get_locations(tzdb); if( locs ) { TzInfo* nfo; TzLocation* loc; for( size_t i = 0; i < locs->len; i++ ) { if( loc = (TzLocation*)locs->pdata[i] ) { if( nfo = tz_info_from_location(loc) ) { if( nfo->utc_offset == tm_gmtoff ) { DEBUGLOGP("%s/%s/%s\n", loc->country, loc->zone, loc->comment); locret = *loc; nforet = *nfo; ret = true; fnd++; } tz_info_free(nfo); if( fnd > 1 ) break; // if( ret ) break; } } } } DEBUGLOGE; return ret && fnd == 1; }
// ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- bool tzn::got(const char* tzcode, TzLocation& locret, TzInfo& nforet, bool exact) { DEBUGLOGB; int fnd = 0; bool ret = false; DEBUGLOGP("requested entry tzcode is %s, exact is %s\n", tzcode, exact ? "on" : "off"); GPtrArray* locs = tz_get_locations(tzdb); if( locs ) { char* tzn = tz_info_get_clean_name(tzdb, tzcode); const char* tzs = tzn ? tzn : (!exact ? tzcode : NULL); if( tzs ) { DEBUGLOGP("requested entry tzcode (cleaned) is %s\n", tzs); TzInfo* nfo; TzLocation* loc; bool got; bool cont_ok, city_ok; const char* cont_db, *city_db; const char* cont_in = strchr (tzs, '/'); // end of continent string for search string const char* city_in = strrchr(tzs, '/'); // begin of city string for search string int cont_il = cont_in ? cont_in-tzs : 0; int city_il = city_in ? strlen(city_in) : 0; DEBUGLOGP("cont_in is %s\n", cont_in); DEBUGLOGP("city_in is %s\n", city_in); if( !exact || (exact && g_quark_try_string(tzs)) ) // NOTE: according to tz.c comments, this will work { for( size_t i = 0; i < locs->len; i++ ) { if( !(loc = (TzLocation*)locs->pdata[i]) ) continue; if( !(nfo = tz_info_from_location(loc)) ) continue; if( !(got = stricmp(loc->zone, tzs) == 0) && !exact ) { cont_db = strchr (loc->zone, '/'); // end of continent string in db city_db = strrchr(loc->zone, '/'); // begin of city string in db if( cont_db != city_db ) { // just compare the 1st and last partitions, i.e., continent and city, // disregarding the 'middle' part, i.e., country or state DEBUGLOGS("tzcode (cleaned) not found and exact is off"); DEBUGLOGS("comparing just the continent and city strings"); DEBUGLOGP("cont_db is %s\n", cont_db); DEBUGLOGP("city_db is %s\n", city_db); cont_ok = cont_in && cont_db && cont_il == (cont_db-loc->zone) && strnicmp(tzs, loc->zone, cont_il) == 0; city_ok = city_in && city_db && city_il == strlen(city_db) && strnicmp(city_in, city_db, city_il) == 0; got = cont_ok && city_ok; DEBUGLOGP("cont_ok is %s, city_ok is %s\n", cont_ok ? "on" : "off", city_ok ? "on" : "off"); } } if( got ) { // DEBUGLOGP("%s/%s/%s\n", loc->country, loc->zone, loc->comment); DEBUGLOGP("%s\n", loc->zone); locret = *loc; nforet = *nfo; ret = true; fnd++; } tz_info_free(nfo); if( fnd > 1 ) break; // if( ret ) break; } } #ifdef DEBUGLOG else DEBUGLOGS("requested entry tzcode (cleaned) not found"); #endif } if( tzn ) g_free(tzn); } DEBUGLOGE; return ret && fnd == 1; }