Pengintai,
I am working on a similar project (to be implemented into a logbook), to calculate how much time is day and night time for a given flight (in case you are sleeping when the sun rises/sets!)
Some of the obstacles are your altitude, giving more day time, as well as the problem of position and time change at the same time. I have thought of a more simple solution where sunset/rise is calculated for departure and destination aerodrome, and then the average is taken. This will be highly inaccurate though, for certain flights.