Android Question Day and night times

harinder

Active Member
Licensed User
Longtime User
Hello..
I wanted to calculate day and night components flying from place A to B, given:
Lat/long of A and B.
Sunrise/sunset times at A and B.
Start time A.
End time B.
Duration = End time - start time
So it could be a duration of 7 hours and start time at A at night 2300(Sunset at A 1830) and end at B at 0600(Sunrise at B 0530). So total night time 06:30 and day time 00:30.
Other combinations like day-night, day-day, night-night also factored in.
I used the Astro lib for sunrise/sunset for A and B.
Can someone guide me on this? Thanks
 

emexes

Expert
Licensed User
How accurate does it need to be? My first thought was that you could rough it out by ignoring latitude and assuming constant travel rate longitudinally and timezonally, but that will present difficulties north of the Arctic Circle (and south of the Antarctic Circle) where sometimes there is no daily sunrise and sunset. I feel like flights that pass through those circles might trip up the ignore-latitude shortcut, but when I had a look at www.flightradar.com there were not many planes venturing that far into the wilderness.

1592807542724.png
 
Upvote 0

harinder

Active Member
Licensed User
Longtime User
Emexes,

It doesen't have to be very accurate. Latitude change can be avoided and as you rightly pointed out, applicable to lower and mid latitutes only, due inaccurate dlat and dlong measuring capabilities. Thanks.



Erel
As UI has only one date entry,ie date of departure, then it can so happen that End time goes into next day. Therefore, I prefer using ticks for times and in such a case, use dateutils.addperiod to add one day to End time.
I actually found working out day and night time calculations a little complicated for me, so asking here..
Rgds..
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You always use ticks to represent time points.
I actually found working out day and night time calculations a little complicated for me, so asking here..
Worth watching the date and time video tutorial: https://www.b4x.com/etp.html

As UI has only one date entry,ie date of departure, then it can so happen that End time goes into next day
There is no problem with using PeriodBetween. However if you are only interested in showing the hours difference (not days) then subtracting the end time with the start time will also work.
 
Upvote 0
Top