Skip to main content

Convert local time to utc time by airport or vise-versa.

This works thanks to data from opentraveldata. The data source is here: https://raw.githubusercontent.com/opentraveldata/opentraveldata/master/opentraveldata/optd_por_public.csv

Usage

Here is the usage:

>>> # import the library
>>> import airporttime

>>> # we are also going to use the datetime library
>>> from datetime import datetime

>>> # create an instance of AirportTime at 'ORD'
>>> apt = airporttime.AirportTime(iata_code='ORD')

>>> # ** side note ** the apt object contains one attribute, basically an instance of a row of data
>>> print(apt.airport.__dict__)
{'iata_code': 'ORD', 'icao_code': 'KORD', 'faa_code': 'ORD', 'is_geonames': 'Y', 'geoname_id': '4887479', 'envelope_id': '', 'name': "Chicago O'Hare International Airport", 'asciiname': "Chicago O'Hare International Airport", 'latitude': '41.978603', 'longitude': '-87.904842', 'fclass': 'S', 'fcode': 'AIRP', 'page_rank': '0.4871606262308594', 'date_from': '', 'date_until': '', 'comment': '', 'country_code': 'US', 'cc2': '', 'country_name': 'United States', 'continent_name': 'North America', 'adm1_code': 'IL', 'adm1_name_utf': 'Illinois', 'adm1_name_ascii': 'Illinois', 'adm2_code': '031', 'adm2_name_utf': 'Cook County', 'adm2_name_ascii': 'Cook County', 'adm3_code': '14000', 'adm4_code': '', 'population': '0', 'elevation': '201', 'gtopo30': '202', 'timezone': 'America/Chicago', 'gmt_offset': '-6.0', 'dst_offset': '-5.0', 'raw_offset': '-6.0', 'moddate': '2018-03-29', 'city_code_list': 'CHI', 'city_name_list': 'Chicago', 'city_detail_list': 'CHI|4887398|Chicago|Chicago', 'tvl_por_list': '', 'iso31662': 'IL', 'location_type': 'A', 'wiki_link': 'https://en.wikipedia.org/wiki/O%27Hare_International_Airport', 'alt_name_section': "de|Flughafen Chicago O'Hare|=wuu|奥黑尔国际机场|=th|ท่าอากาศยานนานาชาติโอแฮร์|=uk|Аеропорт О'Хара|=ta|ஓஹேர் பன்னாட்டு வானூர்தி நிலையம்|=ru|Международный аэропорт Чикаго О'Хара|=ro|Aeroportul Internațional Chicago O'Hare|=pt|Aeroporto Internacional O'Hare|=pnb|اوہیر انٹرنیشنل ہوائی اڈہ|=ja|シカゴ・オヘア国際空港|=mr|ओ'हेर आंतरराष्ट्रीय विमानतळ|=ml|ഒ'ഹെയർ അന്താരാഷ്ട്ര വിമാനത്താവളം|=hu|O’Hare nemzetközi repülőtér|=he|נמל התעופה שיקגו או'הייר|=ko|오헤어 국제공항|=fr|Aéroport international O'Hare de Chicago|=fa|فرودگاه بین\u200cالمللی اوهر شیکاگو|=es|Aeropuerto Internacional O'Hare|=de|Chicago O’Hare International Airport|=cs|Letiště Chicago O'Hare International Airport|=ar|مطار أوهير الدولي|=en|Chicago O'Hare International Airport|p=|Orchard Field|=|O'Hare International Airport|=|Orchard Place/Douglas Field|=sv|Chicago O'Hare flygplats|p", 'wac': '41', 'wac_name': 'Illinois', 'ccy_code': 'USD', 'unlc_list': 'USORD|', 'uic_list': ''}

>>> # suppose you have a naive local datetime you want to convert
>>> naive_loc_time = datetime(2019, 1, 1, 10, 30)

>>> # convert your naive local date and time to utc
>>> tz_aware_utc_time = apt.to_utc(naive_loc_time)
>>> print(tz_aware_utc_time)
2019-02-02 16:30:00+00:00

>>> # convert your tz aware back to local time if you want to
>>> tz_aware_loc_time = apt.from_utc(tz_aware_utc_time)
>>> print(tz_aware_loc_time)
2019-02-02 10:30:00-06:00

>>> # ** side note ** this library internally tries to account daylight savings time (dst)
>>> print(apt._dst(naive_loc_time, tz_aware_loc_time.tzinfo))
False

>>> # if you would like to update the data file, you can use:
>>> airporttime.update()

Metadata

Release files for airporttime 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airporttime 0.0.0
File Size Uploaded
airporttime-0.0.0.tar.gz 3.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for airporttime 0.0.0
File Interpreter ABI Platform
airporttime-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 6.4 MB

Release files / airporttime-0.0.0.tar.gz

Download URL airporttime-0.0.0.tar.gz
Size 3.2 MB
Tags Source
SHA-256 checksum
How to use checksums
651c57d89d2024618f2f04e61c49767dba881029b7959399d692c03cc3f8a8e5
BLAKE2b-256 checksum
How to use checksums
7cf84712fc521f282ad7718a21fb2dacfa47b5111b65e095ba04d93d9d480afc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release files / airporttime-0.0.0-py3-none-any.whl

Download URL airporttime-0.0.0-py3-none-any.whl
Size 3.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
023dcd53446c442ff8e301b6d628dbb5bd04b2df539b50f4a0836e3d989ad041
BLAKE2b-256 checksum
How to use checksums
ddd80fd921be5f9de4b5c321d2ec3f64069c1c90dde180b77c2c04034fb59e6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.5

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page