Find timezone from airport code using perl code - perl

As I am right now working on blocking the particular flight to display if the departing time is with in 3 hours of booking time. As, I need to get the timezone of the departing airport to convert it to GMT and thus get the proper difference between the time of booking and departing time of flight. I have searched for many CPAN modules to do the mapping between the airport code and the timezone but I didn't get any proper solution.It will be great if anybody will helpful to me in finding some good solution to it.

I don't know if you will find a CPAN module, but perhaps you can make a converter yourself - it should be simple enough with a small database table mapping airport codes to timezones.
I found the following link containing a CSV file of over 5,000 airport codes and their timezone relative to UTC.
http://openflights.org/data.html
You can import the CSV from that link into your own database and then have your code work around the timezones and airports in that table.

Related

Display a list of world timezones in flutter

I hate timezones, but this time I can't get by without them. I'm building an app with flutter that needs to preselect the user's timezone but still allow to change it. What timezones should I display?
After doing some research and looking at examples, I noticed 2 patterns
display timezones as city names. Ex "America/Denver"
display timezones as timezones. Ex "Mountain Standart Time"
I decided to go with the city name example because it was the easiest to code. This pattern is used in the "timezone" flutter package, iOS and Android devices, and returned when I query the user's timezone with the "flutter_native_timezone" package. This implementation, however, generated a lot of negative feedback from test users. Most people wanted to see Mountain Standard Time on the list. They also said if I'm using city names for timezones, I should pick the largest city if they share the same timezone. For example, America/Boise and America/Denver should not be displayed together because they're under Mountain Time and the largest should be included.
Can someone explain how I can solve this mess? Doing this manually is possible for 1 country, but doing this for all countries in the world is very tedious and error-prone. I would like to go with the timezone pattern, but this would require some sort of timezone resolution function that can take "America/Denver" and convert it to "Mountain Standart Time" and vice-versa.
I recommend using canonical TZ database names for timezones.
Have you checked timezone package?
This package provides the IANA time zone database and time zone aware DateTime class, TZDateTime.
They offer three different variants of the IANA database:
default: doesn't contain deprecated and historical zones with some
exceptions like "US/Eastern" and "Etc/UTC"; this is about 75% the
size of the all database.
all: contains all data from the IANA time zone database.
10y:default database truncated to contain historical data from 5
years ago until 5 years in the future; this database is about 25% the
size of the default database.

Why to store date as timestamps?

I am creating a node app with mongo and trying to store createdOn field. I have two options, either go with the ISO date format("YYYY-MMM-DDThh:mm:ss.zzz") or use timestamp. My users will be mostly in India but my server is in Oregon USA, and all computation will be done over there. Just wanted your thoughts on which one to use and why?Could not find a nice blog post searching this. I hope the smart people who have already done this would help a fellow newbie out.
What am I already doing?
I am saving the date in the date time format,using momentTimeZone by Asia/Kolkata time and extracting it out. It's very painful and I have to remember that every time I write anything related to date I have to first convert it into IST and then proceed with any ops. Hence require your suggestion, whether to continue like this or try timestamp approach

Alexa skills custom slot for date times

So, I'm working a project with the Amazon Echo. My goal is to record when I did a specific action and to record it into a DB. My issue is timezones, and I avoid this by using epoch time. However, from what I can tell of custom slots for an intent, my choices are formatted date strings with no time, or formatted time strings with no dates, and on top of all of that, I have no way of grabbing the client's timezone without specifically asking for it based on some forum posts I found with my google fu.
Does the echo just hate dates? This seems like something that should be really easy, but I'm struggling to figure out how to go about it without being really awkward and asking where they live so I can do a lookup of their timezone. I already had to make a pivot from telling them the specific time they did something to how long ago they did something because I can't pass dates back to the Echo and expect it to translate it. Is this another silly pivot I have to make?
Correct, you cannot get the client's TZ or location from Alexa. It's a privacy issue. The only way is to ask for it yourself.
There is a custom slot for "five digit number" which is perfect for ZIP code. That is the simplest way to get a user's approximate location.
If you want to get more inventive, since the Echo is (pretty much) only used in America, you only have to narrow it down to one of four time zones. (At the expense of Alaska, Hawaii and Arizona for half the year.) You could just ask which timezone they are in, which is less intrusive.
Or, if you want to get creative, make a joke out of it.
A: "Pop quiz: Are you in Eastern Standard time?"
U: "No"
A: "Drat. Let me guess again. You seem like a Mountain Time person."
...
Yes. It is an irritating limitation. But if you can find a novel way to work around it your skill will be more endearing.
It looks like you cannot (yet) detect the user's timezone, but you should still be able to achieve your goals. A few thoughts:
You could just make the system ignorant of timezones altogether. Each user may have a different timezone, but all times for a particular user will be in the same timezone so any duration calculations will work fine.
There is no DATETIME slot type, so you need to handle each slot separately as AMAZON.DATE and AMAZON.TIME. e.g. "Mark completion on {DATE} at {TIME}"
Also, if you are real-world marking completion datetime, can you just generate the timestamp inside your code, rather than making them say it?
Requesting Zip could be a quick way to set timezone, if necessary.
Hacky: If you use Account Linking you may be able to detect their timezone from the client-side on your login page.
Converting between server timetamp and spoken times in the user's timezone will be problematic, but perhaps you can work around it until amazon includes timezone data.
There is a way to find the user's timezone from country code and postal code which Amazon provides. You just need to enable the permission in the developer's console.
After that, whenever you receive a request from Alexa voice service, you will get a consent token. Which indicates that the user has given the permission.
You can then get the timezone of the user by querying Google API. The python code for the same is mentioned below.
# to get the country code and postal code of user
res = requests.get('{0}/v1/devices/{1}/settings/address/countryAndPostalCode'.format(context.System.apiEndpoint, context.System.device.deviceId),
headers = {'Authorization':'Bearer {}'.format(context.System.apiAccessToken)}).json()
postCode = res['postalCode']
countryCode = res['countryCode']
# key specific to the user
apiAccessKey = 'your-api-key'
# Google Geocoding API: provides latitude and longitude from country code and postal code
res = requests.get('https://maps.googleapis.com/maps/api/geocode/json?address={0},{1}&key={2}'
.format(countryCode, postCode, apiAccessKey)).json()
lat = res['results'][0]['geometry']['location']['lat']
lng = res['results'][0]['geometry']['location']['lng']
# Google's Time Zone API: provides timezone from latitude and longitude.
res = requests.get('https://maps.googleapis.com/maps/api/timezone/json?location={0},{1}&timestamp={2}&key={3}'
.format(lat, lng, datetime.datetime.timestamp(datetime.datetime.now()),apiAccessKey)).json()
timezone = res['timeZoneId']

Strange date format

I am working with a partner who is producing a delimited file for me. The dates are formatted as:
2013.07.06 AD at 01:00:00 GMT
The other company doesn't really have an IT department, so they can't tell me where the format came from. Assuming it is a standard date format, does anyone know which library or database engine would produce this format without a custom format string?
Thank you in advance.
UPDATE:
The partner in question was able to get an answer. For reasons that make no sense to me, the underlying software, written in Java, explicitly formats the date this way, with the " at " and era and time zone indicators. A rather strange choice for a file that is supposed to be consumed by a computer program with no human interaction - they produce a beautiful, human-reasonable Excel file from the same data.
Anyways, thanks for looking and commenting.

Where is the iPhone's Date & Time getting its time zone list

I can get a list of time zones with [NSTimeZone knownTimeZoneNames], but that only gives the time zone IDs which include one or two cities in each time zone.
The Date & Time settings has a great list of cities and I have seen a few other apps that have the same if not similar lookup lists.
Where do these lists come from?
I do need to relate a picked city to its time zone like Date & Time does.
Only 2? On 3.1 the [NSTimeZone knownTimeZoneNames] returns an array of 401 elements, and there are much less than 200 timezones on the Earth.
I'm pretty sure "other apps" use +knownTimeZoneNames as well, since this is the only public method returning such list. Please make sure your code is correct, though.
Settings.app uses the private CPCity API from the private AppSupport.framework. It does have San Francisco, but it's private.
You need to create your own database (the data can be copied from /System/Library/PrivateFrameworks/AppSupport.framework/all_cities_adj.plist).
What you are asking for is commonly referred to as the Olson database. See for instance this Wikipedia page. The public domain Zone.tab file contains all of the timezones. You can find a zones.tab file in the zoneinfo directory of the libical distribution.
I know it might be a late answer, but just in case someone else stumbles on it like I did the other day. I just open sourced a library that does exactly this. It is available as a CocoaPod and you can find it here:
https://github.com/gligorkot/TimeZonePicker
Also, thanks for all the replies above, they helped me in finding the correct cities database that is used for the Settings app.