How should night time be calculated when it is not night during the entire flight? I am B777 rated pilot and software developer. Nowadays I am working on an application about flights and this app has to calculate night time. Still I am trying to figure out how to calculate night time correctly for logging purposes. As you know night definition is easy,

Night means the time between the end of evening civil twilight and the
beginning of morning civil twilight, as published in the Air Almanac,
converted to local time.

But calculating a flight's night time is a little bit confusing.

Is this just related about being day or night at takeoff and landing airports?
Or whole the route should be considered if it is day or night at that time while flying?

I searched a lot but couldn't find any formula or detailed explanation about this. Just found some sites and apps can calculate night time; but interestingly every app gives different result; and still it is unclear for me that how they calculate night time.
Example:
Departure : KMIA
Destination : LTBA
Block Off Time : 03:03Z
Block On Time : 13:36Z
Block Time : 10:33

If you calculate this flight's night time via http://www.crewlogbook.com/utilities/night_calculator.php you will get:
Night Time : 01:47

I wonder how this calculation was made?
By the time that you're operating a 777, the amount of &quot;night&quot; time in the logbook is probably of little to no concern, so getting things exactly right to the minute may not be a great worry.
I'd simply grab a location every 15 minutes, either by GPS if your app has that, or else as (time elapsed / total time) * total great circle distance, and then for that location determine if you're between EECT &amp; BMCT at that time. If so, log those minutes as night.
You could get fancier by interpolating the BMCT (for instance) between the last point you were in &quot;night&quot; and the first point you weren't. Then you have &quot;the&quot; time that you passed from night into day.
To implement that, you'll need to calculate the EECT &amp; BMCT for an given point, plus find points along the great circle route. I'd expect that algorithms are available for both of those functions, but it's not something I've ever implemented.