Thursday, October 3, 2019

Local time

What time is it?  Generally, there are two answers to that question: what time is it where I am, and what time is it in UTC (Zulu).

All times in MyFlightbook are in Zulu (UTC) time, for a pretty obvious reason: it's the only way to do computations.  If you depart at 4PM EST and land at 7PM PST, you're flight was 6 hours long, not 3, after all; as with all math, you need to use common units.  And in order to compute things like night flight, one needs to know the position of the sun relative to the horizon at a given latitude/longitude and time - and thus the time needs to also be in a common unit system.

The iOS and Android apps on MyFlightbook have an option to use local time.  When this is selected, all the times are still in UTC.  The only difference is in the display.  So in the example above, if you enter "4PM" while you are in New York (EST = UTC-4), that goes into the database as 8PM UTC (2000Z).  When you land at 7PM in LA (PST=UTC-7), that 7PM goes into the database as 2AM (0200Z) the next day.

What's interesting is that if you go and look at your New York departure time after your landing in LA, it will no longer say 4PM - it will say 1PM.  Why?  Because you're now in LA, and it's displaying the unmodified 2000Z departure time in PST, (2000Z-0700=1300PST).  Note that the underlying time is invariant; only the display has changed.

That works well on the device, which typically always knows its location and its timezone offset.  It also works for times that are either entered in UTC, or which are entered relative to your current time zone offset.

But the key thing is that the local time option always works based on *where you are* *right now*.  I.e., it's not based on the time or location of the flight data, it's based on your time and location as the viewer of that data.

Unfortunately, converting from local time to UTC - especially for other than the "right here, right now" case - is a significantly more complicated problem.

E.g., if you are going through old flights and want to log something that departed ABC at 4PM local and arrived at DEF at 7PM local on Oct 23, 1997, you need to know the timezone offset for ABC and for DEF on those dates, including if/when Daylight Saving time is observed (and, if it is observed, when the cut-over dates are)

This is absolutely a solvable problem, but requires a lot of data and it requires maintenance of that data.  Specifically, it requires:
  • A database of geographic boundaries of each time zone, including changes over time.
  • A database of daylight saving time rules, including changes in those rules over time.
So to compute, say, total time for a flight with local departure/arrival times specified:
  • Look up the latitude/longitude of the departure or arrival airport on the date of departure/arrival
  • Find the appropriate time zone based on those coordinates
  • Determine whether or not to apply daylight saving time based on the date of flight, taking care of the time of arrival (since a flight can span the typical 2am-local transition to/from daylight saving time)
  • Adjust the local times based on the offsets computed above.
MyFlightbook does not do the above conversions.  Why?  Money.  There are services which can do precisely the computations above, but because of the large data set and the maintenance required to keep up with ever changing timezone rules, these are not free.  As a free service, it's dangerous for me to offer functionality that could result in unbounded potential expense.

For this reason, my suggestion is to convert local time to UTC before entering historical flights.

No comments:

Post a Comment