jpatokal / openflights

Website for storing flight information, rendering paths on a zoomable world map and calculating statistics, with plenty of free airline, airport and route data.
http://openflights.org
GNU Affero General Public License v3.0
1.4k stars 393 forks source link

[Bug] Arrival time calculation fails for full hours [sf#196] #194

Open jpatokal opened 9 years ago

jpatokal commented 9 years ago

Reported by strainu on 2014-09-28 17:56 UTC Try to input the following data into openflights:

Departure time: 07:00 Departure: OTP Arrival: TSR

The arrival time is automatically set to 7:60 (without leading 0) instead of 08:00.

Issues I see:

jpatokal commented 9 years ago

Commented by jpatokal on 2014-09-28 22:20 UTC Thanks for the report, but I'm unable to replicate that on Firefox (I get "01:00"), nor do I see how that's possible. The code in question says:

mins = Math.round((Math.abs(duration) % 1.0) * 60);
if(mins == 60) {
  mins = 0;
  hours++;
}

Math,round returns an integer, so if mins == 60, it should get converted to 1:00. What browser are you using?

jpatokal commented 9 years ago

Commented by strainu on 2014-09-29 02:39 UTC The bug was found on the latest Chrome for ChromeOS, but I can confirm it can be reproduced on Firefox for Android 30.0

jpatokal commented 9 years ago

Commented by strainu on 2014-09-29 02:55 UTC Also, that mod 1.0 seems to me like exploiting some quirk in the language used. You should be only using operations with a correspondence in real mathematics.

jpatokal commented 9 years ago

Commented by jpatokal on 2014-09-29 12:24 UTC I'm still unable to replicate, but you're right, that code is hacky as hell. I've replaced it with a much more sane way of doing this, any better now?

  hours = Math.floor(dst_time);
  mins = Math.floor((dst_time-hours) * 60);
jpatokal commented 9 years ago

Commented by strainu on 2014-09-29 16:31 UTC Kindof sortof :)

I now get an arrival time of 07:59 - I can't calculate by hand the correct result (either 59 or 60 minutes). Perhaps this would work better:

mins = Math.round((dst_time-hours) * 60); 

Here is the full platform I have: Google Chrome 36.0.1985.138 (Creat oficial 285304) Platformă 5841.83.0 (Official Build) stable-channel peppy Blink 537.36 (@178689) JavaScript V8 3.26.31.11