Of course, I don't want it to be the most accurate daylight-calculator ever, it's for a game, and I'm alright with writing it within loose conventional values.
1) I'm not taking into account leap years, nor DST, nor wariations due to longitude or other factors.
2) I've set equinoxes and solstices at fixed dates: Spring eq = 3/21; Summer sol = 6/21; Autumn eq = 9/22; Winter sol = 12/20.
3) I've gathered approximative data about daylight times at equinoxes and solstices at latitude 0 (equator), 30, 60, and 90 (either pole, I don't differentiate between north and south, assuming it's exactly the same for both), which are the four groups of four variables being set you can see at the bottom of the macro.
This is the macro now, with no other calculation than chosen date (chosen by the user of the macro) and equinoxes/solstices dates:
Spoiler
Code: Select all
[h: abort(input(
"month|1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12|Month|LIST",
"day|1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31|Day|LIST",
"Latitude|45|Latitude (approx.)"
))]
[h: month = month + 1]
[h: day = day + 1]
[h: daysInMonth1 = 31]
[h: daysInMonth2 = 28]
[h: daysInMonth3 = 31]
[h: daysInMonth4 = 30]
[h: daysInMonth5 = 31]
[h: daysInMonth6 = 30]
[h: daysInMonth7 = 31]
[h: daysInMonth8 = 31]
[h: daysInMonth9 = 30]
[h: daysInMonth10 = 31]
[h: daysInMonth11 = 30]
[h: daysInMonth12 = 31]
[h: dayOfSpringEq = daysInMonth1 + daysInMonth2 + 21]
[h: dayOfSummerSol = daysInMonth1 + daysInMonth2 + daysInMonth3 + daysInMonth4 + daysInMonth5 + 21]
[h: dayOfAutumnEq = daysInMonth1 + daysInMonth2 + daysInMonth3 + daysInMonth4 + daysInMonth5 + daysInMonth6 + daysInMonth7 + daysInMonth8 + 22]
[h: dayOfWinterSol = daysInMonth1 + daysInMonth2 + daysInMonth3 + daysInMonth4 + daysInMonth5 + daysInMonth6 + daysInMonth7 + daysInMonth8 + daysInMonth9 + daysInMonth10 + daysInMonth11 + 20]
[h: selectedDate = day]
[h, if(month > 1): selectedDate = selectedDate + daysInMonth1]
[h, if(month > 2): selectedDate = selectedDate + daysInMonth2]
[h, if(month > 3): selectedDate = selectedDate + daysInMonth3]
[h, if(month > 4): selectedDate = selectedDate + daysInMonth4]
[h, if(month > 5): selectedDate = selectedDate + daysInMonth5]
[h, if(month > 6): selectedDate = selectedDate + daysInMonth6]
[h, if(month > 7): selectedDate = selectedDate + daysInMonth7]
[h, if(month > 8): selectedDate = selectedDate + daysInMonth8]
[h, if(month > 9): selectedDate = selectedDate + daysInMonth9]
[h, if(month > 10): selectedDate = selectedDate + daysInMonth10]
[h, if(month > 11): selectedDate = selectedDate + daysInMonth11]
[h: minutesInADay = 1440]
[h: lat0MinOfLightSpringEq = 726]
[h: lat0MinOfLightSummerSol = 727]
[h: lat0MinOfLightAutumnEq = 726]
[h: lat0MinOfLightWinterSol = 727]
[h: lat30MinOfLightSpringEq = 726]
[h: lat30MinOfLightSummerSol = 845]
[h: lat30MinOfLightAutumnEq = 727]
[h: lat30MinOfLightWinterSol = 652]
[h: lat60MinOfLightSpringEq = 730]
[h: lat60MinOfLightSummerSol = 1132]
[h: lat60MinOfLightAutumnEq = 732]
[h: lat60MinOfLightWinterSol = 612]
[h: lat90MinOfLightSpringEq = 742]
[h: lat90MinOfLightSummerSol = 1304]
[h: lat90MinOfLightAutumnEq = 738]
[h: lat90MinOfLightWinterSol = 225]
I tried to imagine a cartesian plane where X is the number of the days and Y the number of the latitude, with the fixed daylight values as points on the plane, but in the end, after much struggling, I only ended up with my head all messed up.
I'm no mathematician, and I need the help of someone who's better than me at math (and has a fresh mind about this thing).
How can I calculate the number of minutes of daylight at any given date and latitude that is not one of the fixed values?