Skip to content

Commit

Permalink
Made the Sunrise and sunset times correct for British Summer time.
Browse files Browse the repository at this point in the history
  • Loading branch information
zizwiz committed May 16, 2024
1 parent 43690ee commit f6fe486
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 21 deletions.
20 changes: 10 additions & 10 deletions myFlightInfo/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions myFlightInfo/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void btn_reset_Click(object sender, EventArgs e)
lbl_d_airport_name.Text = "";
lbl_to_pressure.Text = "";

dateTimePicker1.Value = DateTime.Now;
NavigationDateTimePicker.Value = DateTime.Now;

lstbx_navigation_from.Items.Clear();
lstbx_navigation_to.Items.Clear();
Expand Down Expand Up @@ -245,9 +245,9 @@ private void btn_calculate_altimiter_Click(object sender, EventArgs e)
*/

int year = dateTimePicker1.Value.Year;
int month = dateTimePicker1.Value.Month;
int day = dateTimePicker1.Value.Day;
int year = NavigationDateTimePicker.Value.Year;
int month = NavigationDateTimePicker.Value.Month;
int day = NavigationDateTimePicker.Value.Day;
int hour = DateTime.Now.Hour;
int minute = DateTime.Now.Minute;
int second = DateTime.Now.Second;
Expand Down Expand Up @@ -308,9 +308,9 @@ private void cmbobx_airport_info_SelectedIndexChanged(object sender, EventArgs e
{
grpbx_towns.Visible = false;

int year = dateTimePicker1.Value.Year;
int month = dateTimePicker1.Value.Month;
int day = dateTimePicker1.Value.Day;
int year = NavigationDateTimePicker.Value.Year;
int month = NavigationDateTimePicker.Value.Month;
int day = NavigationDateTimePicker.Value.Day;

//we use flags as the info in the xml file we will use may not be complete
//we only show info if it is complete.
Expand Down Expand Up @@ -361,9 +361,9 @@ private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
((lbl_d_airport_name.Text != "..") && (lbl_d_airport_name.Text != "")))
{

int year = dateTimePicker1.Value.Year;
int month = dateTimePicker1.Value.Month;
int day = dateTimePicker1.Value.Day;
int year = NavigationDateTimePicker.Value.Year;
int month = NavigationDateTimePicker.Value.Month;
int day = NavigationDateTimePicker.Value.Day;

Navigate.SolarInfo(lbl_p_airport_name.Text, lstbx_navigation_from, year, month, day);
Navigate.SolarInfo(lbl_d_airport_name.Text, lstbx_navigation_to, year, month, day);
Expand Down
17 changes: 17 additions & 0 deletions myFlightInfo/Navigation/Navigate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ public static void SolarInfo(string airfield, ListBox myListBox, int year, int m

Sunriset.SunriseSunset(year, month, day, lat, lng, out double tsunrise, out double tsunset);

//Find last Sunday in March and October of year in datepicker
DateTime marchDate = CheckDate.LastSundayOfMonth("3", year.ToString());
DateTime octoberDate = CheckDate.LastSundayOfMonth("10", year.ToString());
// Construct the chosen date we are looking at
DateTime DateToCheck = DateTime.Parse(day + "/" + month + "/" + year + " 00:00:00");

//Are we in BritishSummerTime for chosen date?
//We only fly in daylight so no need to worry about the hour.
bool BritishSummerTime = marchDate <= DateToCheck && DateToCheck <= octoberDate;

if (BritishSummerTime)
{
tsunrise += 1;
tsunset += 1;
}


if (NumItems >= 12)
{
//If we are updating then delete and add again
Expand Down
21 changes: 21 additions & 0 deletions myFlightInfo/common_data/BSTorGMT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace myFlightInfo.common_data
{
class CheckDate
{
public static DateTime LastSundayOfMonth(string month, string year)
{
int myyear = Convert.ToInt32(year);
int mymonth = Convert.ToInt32(month);
var myDayOfWeek = DayOfWeek.Sunday;

DateTime date = new DateTime(myyear, mymonth, DateTime.DaysInMonth(myyear, mymonth), System.Globalization.CultureInfo.CurrentCulture.Calendar);

int daysOffset = date.DayOfWeek - myDayOfWeek;
if (daysOffset < 0) daysOffset += 7; // if the code is negative, we need to normalize them

return DateTime.Parse(date.AddDays(-daysOffset).ToLongDateString());
}
}
}
5 changes: 4 additions & 1 deletion myFlightInfo/myFlightInfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="AreYouSure.Designer.cs">
<DependentUpon>AreYouSure.cs</DependentUpon>
</Compile>
<Compile Include="common_data\BSTorGMT.cs" />
<Compile Include="CrossWind.cs">
<SubType>Form</SubType>
</Compile>
Expand All @@ -85,7 +86,9 @@
<Compile Include="compliance_data\aircraftName.Designer.cs">
<DependentUpon>aircraftName.cs</DependentUpon>
</Compile>
<Compile Include="compliance_data\compliance_data.cs" />
<Compile Include="compliance_data\compliance_data.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="crosswind\Crosswind.cs" />
<Compile Include="Form1.cs">
<SubType>Form</SubType>
Expand Down

0 comments on commit f6fe486

Please sign in to comment.