I've received many requests over the years to support local time when importing flights, particularly for airline pilots who have schedules that are provided in local time.
I've always pushed back on this because it's a genuinely hard problem to solve; see my earlier post about what was required.
Alas, perhaps I just needed to look harder. I finally found the right google queries to lead me to a free library that will convert a latitude/longitude to a time zone descriptor that is sufficiently narrow that a second library can convert local time to UTC with reasonable reliability.
Finding the right tools was absolutely the hard part; integrating them was somewhat easier, so now on import there is an option that allows you to tell MyFlightbook that your input times (block out/in, engine start/stop, or flight start/stop) are in local time rather than in UTC.
I still advice using this option with care. Allow me to explain why.
I can't do any meaningful computation on local times; everything has to be UTC for autofill to work. Think about it: Boston to Chicago is a 2-hour flight by jet, but Chicago is an hour behind Boston. So if you leave Boston at 10am, you arrive at 11am; if you leave Chicago at 10am, you arrive in Boston at 1pm. Using local times would imply that it's three times as long to go eastbound than westbound!
But how and when do I convert from local to UTC?
- First, if you have a flight path (GPX, KML, CSV recorded by the app), then I already have time-stamped UTC data and I don't do any local time conversion. There's no need - the flight path tells me everything I need, so the block/engine/flight times you provide can be safely ignored
- If you don't have a flight path, I look at the airports in your route. If I don't find EXACTLY two airports that match distinct airports in the database, then I can't determine which airport was when, so I cannot do any local time conversion. In this case, minimal autofill will happen, but you could still find some wonkiness: if you didn't specify a total time, then I will compute it as if everything were UTC. So in the Chicago example above, you might get 1 hour or 3 hours instead of 2. (If you've provided a total time, though, then it won't be overwritten).
- If you do, however, have exactly 2 airports in your route, then the system will:
- Compute the UTC time at departure and destination, using the airport's latitudes/longitudes and the block/engine/flight times as appropriate, converting them from their respective local times.
- Construct a synthetic great-circle path from A to B and evenly space out the samples across it, both in space and in time.
- Clear the provided Total Time and Night Time fields (and a few others) so that they can be recomputed from the path.
- "Fly" the synthetic path to determine things like night and total time, filling them in and computing engine start/stop, in UTC, based on the start/end of the path
- The lookup of the time zone from the latitude/longitude may not hit a time zone
- The time zone returned by the lookup may not be found by the system that converts from local time
- Time zone boundaries and rules (especially daylight time!) change over time and may not be reflected correctly
- There are (rare) corner cases that are fundamentally problematic. E.g., 1:30am on the date that DST ends is ambiguous because it occurs twice, and it is problematic on the date that DST begins because it doesn't happen at all!!
No comments:
Post a Comment