Skip to main content

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

Project description

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airporttime-0.0.0.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

airporttime-0.0.0-py3-none-any.whl (3.2 MB view details)

Uploaded Python 3

File details

Details for the file airporttime-0.0.0.tar.gz.

File metadata

  • Download URL: airporttime-0.0.0.tar.gz
  • Upload date:
  • Size: 3.2 MB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for airporttime-0.0.0.tar.gz
Algorithm Hash digest
SHA256 651c57d89d2024618f2f04e61c49767dba881029b7959399d692c03cc3f8a8e5
MD5 c3f586e8a9da89c01c4f4c8f108e30de
BLAKE2b-256 7cf84712fc521f282ad7718a21fb2dacfa47b5111b65e095ba04d93d9d480afc

See more details on using hashes here.

File details

Details for the file airporttime-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: airporttime-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.2 MB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for airporttime-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 023dcd53446c442ff8e301b6d628dbb5bd04b2df539b50f4a0836e3d989ad041
MD5 0d2bd3a0535c30c95460c5ef00367ed4
BLAKE2b-256 ddd80fd921be5f9de4b5c321d2ec3f64069c1c90dde180b77c2c04034fb59e6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page