mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-26 20:59:27 +01:00
Geography: Always prefer IANA timezones over UTC offsets
Even if the UTC offsets are given on a more specific entity, they are usually worthless to us (eg. DST).
This commit is contained in:
parent
76b9d6f0ce
commit
d2091e8f71
@ -180,6 +180,12 @@ class GeographyWikidataTestCase(SupyTestCase):
|
||||
utils.time.iana_timezone("America/New_York"),
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
# Paris, France
|
||||
wikidata.timezone_from_uri("http://www.wikidata.org/entity/Q90"),
|
||||
utils.time.iana_timezone("Europe/Paris"),
|
||||
)
|
||||
|
||||
@skipIf(not network, "Network test")
|
||||
def testParentQualifiedIgnorePreferred(self):
|
||||
# The queried object does not have a TZ property,
|
||||
|
@ -79,6 +79,9 @@ SELECT ?item ?itemLabel ?rank ?endtime ?appliestopart ?utcoffset ?tzid (MIN(?are
|
||||
# Get the area, will be used to order by specificity
|
||||
OPTIONAL { ?statementsubject wdt:P2046 ?area. }
|
||||
|
||||
# Require that ?timezone be an instance of...
|
||||
?timezone (wdt:P31/wdt:P279*) <$tztype>.
|
||||
|
||||
{
|
||||
# Get either an IANA timezone ID...
|
||||
?timezone wdt:P6687 ?tzid.
|
||||
@ -130,7 +133,11 @@ def _query_sparql(query):
|
||||
def timezone_from_uri(location_uri):
|
||||
"""Returns a :class:datetime.tzinfo object, given a Wikidata Q-ID.
|
||||
eg. ``"Q60"`` for New York City."""
|
||||
data = _query_sparql(TIMEZONE_QUERY.substitute(subject=location_uri))
|
||||
for tztype in [
|
||||
"http://www.wikidata.org/entity/Q17272692", # IANA timezones first
|
||||
"http://www.wikidata.org/entity/Q12143", # any timezone as a fallback
|
||||
]:
|
||||
data = _query_sparql(TIMEZONE_QUERY.substitute(subject=location_uri, tztype=tztype))
|
||||
results = data["results"]["bindings"]
|
||||
for result in results:
|
||||
if "tzid" in result:
|
||||
|
Loading…
Reference in New Issue
Block a user