Skip to content

Commit 0e93934

Browse files
authored
Merge pull request #233 from Tronald/develop
2.22.1.1
2 parents ef8382c + f703110 commit 0e93934

File tree

6 files changed

+143
-33
lines changed

6 files changed

+143
-33
lines changed

CoordinateSharp.Magnetic/CoordinateSharp.Magnetic.csproj

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,21 @@ For more information, please contact Signature Group, LLC at this address: sales
4747
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70; net80</TargetFrameworks>
4848
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
4949
<GenerateDocumentationFile>true</GenerateDocumentationFile>
50-
<Version>1.1.11.0</Version>
50+
<Version>1.1.12.0</Version>
5151
<Authors>Signature Group, LLC</Authors>
5252
<Company />
5353
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
5454
<PackageLicenseUrl></PackageLicenseUrl>
55-
<Copyright>Copyright 2023</Copyright>
55+
<Copyright>Copyright 2024</Copyright>
5656
<Description>CoordinateSharp magnetic data extensions.</Description>
57-
<PackageReleaseNotes>-Adds NET 8.0 support.
58-
-Maps to latest CoordinateSharp version.</PackageReleaseNotes>
57+
<PackageReleaseNotes>-Maps to latest CoordinateSharp version.</PackageReleaseNotes>
5958
<PackageTags>CoordinateSharp Latitude Longitude Coordinates Geography Magnetic Declination</PackageTags>
6059
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
6160
<PackageLicenseFile>License.txt</PackageLicenseFile>
6261
<PackageIconUrl></PackageIconUrl>
6362
<PackageId>CoordinateSharp.Magnetic</PackageId>
6463
<Title>CoordinateSharp.Magnetic</Title>
65-
<AssemblyVersion>1.1.11.0</AssemblyVersion>
64+
<AssemblyVersion>1.1.12.0</AssemblyVersion>
6665
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
6766
<SignAssembly>true</SignAssembly>
6867
<PackageIcon>128x128.png</PackageIcon>

CoordinateSharp/Celestial/Celestial.Model.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public partial class Celestial
6161
internal DateTime? moonSet;
6262
internal DateTime? moonRise;
6363

64+
internal TimeSpan daySpan;
65+
internal TimeSpan nightSpan;
66+
6467
internal DateTime? solarNoon;
6568

6669
internal double sunAltitude;
@@ -195,6 +198,16 @@ public partial class Celestial
195198
/// Sun azimuth in degrees (E of N).
196199
/// </summary>
197200
public double SunAzimuth { get { return sunAzimuth; } }
201+
202+
/// <summary>
203+
/// Daylight time span for date and location.
204+
/// </summary>
205+
public TimeSpan DaySpan { get { return daySpan; } }
206+
/// <summary>
207+
/// Night time span for date and location.
208+
/// </summary>
209+
public TimeSpan NightSpan { get { return nightSpan; } }
210+
198211
/// <summary>
199212
/// Moon altitude in degrees (E of N) (corrected for parallax and refraction).
200213
/// </summary>

CoordinateSharp/Celestial/Celestial.StaticMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ public static Solstices Get_Solstices(DateTime d)
10451045
public static Solstices Get_Solstices(DateTime d, double offset)
10461046
{
10471047
Celestial c = new Celestial();
1048-
SunCalc.Calculate_Soltices_Equinoxes(d, c, offset);
1048+
SunCalc.Calculate_Solstices_Equinoxes(d, c, offset);
10491049
return c.Solstices;
10501050
}
10511051

@@ -1069,7 +1069,7 @@ public static Equinoxes Get_Equinoxes(DateTime d)
10691069
public static Equinoxes Get_Equinoxes(DateTime d, double offset)
10701070
{
10711071
Celestial c = new Celestial();
1072-
SunCalc.Calculate_Soltices_Equinoxes(d, c, offset);
1072+
SunCalc.Calculate_Solstices_Equinoxes(d, c, offset);
10731073
return c.Equinoxes;
10741074
}
10751075

CoordinateSharp/Celestial/Solar/SunCalculations.cs

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace CoordinateSharp
5050
{
5151
internal class SunCalc
5252
{
53-
public static void CalculateSunTime(double lat, double longi, DateTime date, Celestial c, EagerLoad el, double offset)
53+
public static void CalculateSunTime(double lat, double lng, DateTime date, Celestial c, EagerLoad el, double offset)
5454
{
5555

5656
if (date.Year == 0001) { return; } //Return if date value hasn't been established.
@@ -61,7 +61,7 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
6161
////Sun Time Calculations
6262
//Get solar coordinate info and feed
6363
//Get Julian
64-
double lw = rad * -longi;
64+
double lw = rad * -lng;
6565
double phi = rad * lat;
6666

6767
//Rise Set
@@ -77,17 +77,18 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
7777
var celC = Get_Solar_Coordinates(date, -offset);
7878
c.solarCoordinates = celC;
7979
//Azimuth and Altitude
80-
CalculateSunAngle(date.AddHours(-offset), longi, lat, c, celC); //SUBTRACT OFFSET TO CALC IN Z TIME AND ADJUST SUN ANGLE DURING LOCAL CALCULATIONS.
80+
CalculateSunAngle(date.AddHours(-offset), lng, lat, c, celC); //SUBTRACT OFFSET TO CALC IN Z TIME AND ADJUST SUN ANGLE DURING LOCAL CALCULATIONS.
8181
// neither sunrise nor sunset
8282
if ((!c.SunRise.HasValue) && (!c.SunSet.HasValue))
8383
{
8484
if (c.SunAltitude < 0)
8585
{
8686
c.sunCondition = CelestialStatus.DownAllDay;
87+
8788
}
8889
else
8990
{
90-
c.sunCondition = CelestialStatus.UpAllDay;
91+
c.sunCondition = CelestialStatus.UpAllDay;
9192
}
9293
}
9394
// sunrise or sunset
@@ -104,7 +105,15 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
104105
// No sunset this date
105106
c.sunCondition = CelestialStatus.NoSet;
106107
}
108+
else
109+
{
110+
111+
}
107112
}
113+
114+
//Sat day and night time spans within 24 hours period
115+
Set_DayNightSpan(c);
116+
108117
//Additional Times
109118
c.additionalSolarTimes = new AdditionalSolarTimes();
110119
//Dusk and Dawn
@@ -128,10 +137,13 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
128137
//BottomDisc
129138
evDate = Get_Event_Time(lw, phi, -.2998, actualDate, offset, false);
130139
c.AdditionalSolarTimes.sunriseBottomDisc = evDate[0];
131-
c.AdditionalSolarTimes.sunsetBottomDisc = evDate[1];
140+
c.AdditionalSolarTimes.sunsetBottomDisc = evDate[1];
141+
142+
//Day Night Span
143+
132144
}
133-
if (el.Extensions.Solstice_Equinox){ Calculate_Soltices_Equinoxes(date, c, offset); }
134-
if (el.Extensions.Solar_Eclipse) { CalculateSolarEclipse(date, lat, longi, c); }
145+
if (el.Extensions.Solstice_Equinox){ Calculate_Solstices_Equinoxes(date, c, offset); }
146+
if (el.Extensions.Solar_Eclipse) { CalculateSolarEclipse(date, lat, lng, c); }
135147
}
136148
/// <summary>
137149
/// Gets time of event based on specified degree below specified altitude
@@ -224,7 +236,43 @@ public static void CalculateSunTime(double lat, double longi, DateTime date, Cel
224236
}
225237
return target;
226238
}
227-
239+
private static void Set_DayNightSpan(Celestial c)
240+
{
241+
if(c.sunCondition == CelestialStatus.RiseAndSet)
242+
{
243+
//Need to handle set before rise for UTC and timezone adjustments.
244+
if(c.sunSet>c.SunRise)
245+
{
246+
c.daySpan= c.sunSet.Value.TimeOfDay - c.SunRise.Value.TimeOfDay;
247+
c.nightSpan = new TimeSpan(24, 0, 0) - c.daySpan;
248+
}
249+
else
250+
{
251+
c.nightSpan = c.sunRise.Value.TimeOfDay - c.SunSet.Value.TimeOfDay;
252+
c.daySpan = new TimeSpan(24, 0, 0) - c.nightSpan;
253+
}
254+
}
255+
else if(c.sunCondition == CelestialStatus.DownAllDay)
256+
{
257+
c.nightSpan= new TimeSpan(24, 0, 0);
258+
c.daySpan = new TimeSpan(0);
259+
}
260+
else if(c.sunCondition == CelestialStatus.UpAllDay)
261+
{
262+
c.daySpan = new TimeSpan(24, 0, 0);
263+
c.nightSpan = new TimeSpan(0);
264+
}
265+
else if(c.sunCondition == CelestialStatus.NoRise)
266+
{
267+
c.nightSpan = new TimeSpan(24, 0, 0) - c.sunSet.Value.TimeOfDay;
268+
c.daySpan = c.sunSet.Value.TimeOfDay;
269+
}
270+
else if(c.sunCondition == CelestialStatus.NoSet)
271+
{
272+
c.daySpan= new TimeSpan(24, 0, 0) - c.sunRise.Value.TimeOfDay;
273+
c.nightSpan = c.sunRise.Value.TimeOfDay;
274+
}
275+
}
228276
public static void CalculateZodiacSign(DateTime date, Celestial c)
229277
{
230278
//Aquarius (January 20 to February 18)
@@ -304,11 +352,11 @@ public static void CalculateZodiacSign(DateTime date, Celestial c)
304352
return;
305353
}
306354
}
307-
public static void CalculateSolarEclipse(DateTime date, double lat, double longi, Celestial c)
355+
public static void CalculateSolarEclipse(DateTime date, double lat, double lng, Celestial c)
308356
{
309357
//Convert to Radian
310358
double latR = lat * Math.PI / 180;
311-
double longR = longi * Math.PI / 180;
359+
double longR = lng * Math.PI / 180;
312360
List<List<string>> se = SolarEclipseCalc.CalculateSolarEclipse(date, latR, longR);
313361
//RETURN FIRST AND LAST
314362
if (se.Count == 0) { return; }
@@ -338,7 +386,7 @@ public static void CalculateSolarEclipse(DateTime date, double lat, double longi
338386
}
339387
}
340388

341-
public static void Calculate_Soltices_Equinoxes(DateTime d, Celestial c, double offset)
389+
public static void Calculate_Solstices_Equinoxes(DateTime d, Celestial c, double offset)
342390
{
343391
double springEquinoxJDE;
344392
double fallEquinoxJDE;
@@ -504,12 +552,12 @@ private static void CalculateSunAngle(DateTime date, double longi, double lat, C
504552
c.sunAzimuth = ang[0];
505553
c.sunAltitude = ang[1];
506554
}
507-
public static double[] CalculateSunAngle(DateTime date, double longi, double lat, SolarCoordinates solC)
555+
public static double[] CalculateSunAngle(DateTime date, double lng, double lat, SolarCoordinates solC)
508556
{
509557
TimeSpan ts = date - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
510558
double dms = (ts.TotalMilliseconds / dayMS - .5 + j1970) - j2000;
511559

512-
double lw = rad * -longi;
560+
double lw = rad * -lng;
513561
double phi = rad * lat;
514562
double e = rad * 23.4397;
515563

CoordinateSharp/CoordinateSharp.csproj

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,26 @@ Please visit http://coordinatesharp.com/licensing or contact Signature Group, LL
5050
<TargetFrameworks>net40; netstandard1.3; netstandard1.4; netstandard2.0; netstandard2.1; net50; net60; net70; net80</TargetFrameworks>
5151
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
5252
<GenerateDocumentationFile>true</GenerateDocumentationFile>
53-
<Version>2.21.1.1</Version>
53+
<Version>2.22.1.1</Version>
5454
<Authors>Signature Group, LLC</Authors>
5555
<Company />
5656
<PackageProjectUrl>https://github.com/Tronald/CoordinateSharp</PackageProjectUrl>
5757
<PackageLicenseUrl></PackageLicenseUrl>
58-
<Copyright>Copyright 2023</Copyright>
58+
<Copyright>Copyright 2024</Copyright>
5959
<Description>CoordinateSharp is a high powered, lightweight .NET library that can convert geographical coordinates, perform distance logic, and calculate location based sun, moon, and magnetic information with minimal code.</Description>
60-
<PackageReleaseNotes>-Adds accessible Magnitude and Coverage property values to the SolarEclipseDetails class.
61-
-Adds accessible Penumbral and Umbral Magnitude property values to the LunarEclipseDetails class.
62-
-Add NET 8.0 support.
63-
-Adds correctly named 'PartialEclipseEnd' property to 'SolarEclipseDetails' and deprecates incorrectly named property.</PackageReleaseNotes>
60+
<PackageReleaseNotes>-Adds Day and Night TimeSpan properties to the CelestialInfo class for easier calculation of total day and night hours for a date at a specified location.</PackageReleaseNotes>
6461
<PackageTags>Conversion; Latitude; Longitude; Coordinates; Geography; Sun; Moon; Solar; Lunar; Time; MGRS; UTM; EPSG:3857; ECEF; GEOREF; Web Mercator;</PackageTags>
6562
<!-- <PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>-->
6663
<PackageLicenseFile>License.txt</PackageLicenseFile> <PackageIconUrl></PackageIconUrl>
6764
<PackageId>CoordinateSharp</PackageId>
6865
<Title>CoordinateSharp</Title>
69-
<AssemblyVersion>2.21.1.1</AssemblyVersion>
66+
<AssemblyVersion>2.22.1.1</AssemblyVersion>
7067
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
7168
<SignAssembly>true</SignAssembly>
7269
<PackageIcon>128x128.png</PackageIcon>
7370
<AssemblyOriginatorKeyFile>CoordinateSharp Strong Name.snk</AssemblyOriginatorKeyFile>
7471
<DelaySign>false</DelaySign>
75-
<FileVersion>2.21.1.1</FileVersion>
72+
<FileVersion>2.22.1.1</FileVersion>
7673
<RepositoryUrl>https://github.com/Tronald/CoordinateSharp</RepositoryUrl>
7774
<PackageReadmeFile>README.md</PackageReadmeFile>
7875
<SymbolPackageFormat>snupkg</SymbolPackageFormat>

CoordinateSharp_UnitTests/Celestial.Solar.cs

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Microsoft.VisualStudio.TestTools.UnitTesting;
1+
// Ignore Spelling: Azs Astro
2+
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
24
using System;
35
using CoordinateSharp;
46
using System.Reflection;
@@ -82,7 +84,7 @@ public CelestialSolar()
8284
//THESE OBJECT ARE TESTED AGAINST SERIALIZED OBJECTS.
8385
//IF CHANGING THE MODEL YOU WILL HAVE TO CHANGE THE OBJECTS THEY ARE TESTED AGAINST AS WELL
8486

85-
data.SolarEclispe = c.CelestialInfo.SolarEclipse;
87+
data.SolarEclipse = c.CelestialInfo.SolarEclipse;
8688

8789
}
8890
/// <summary>
@@ -181,8 +183,8 @@ public void SolarEclipses()
181183
SolarEclipse ev = c.CelestialInfo.SolarEclipse;
182184
SolarEclipseDetails lE1 = ev.LastEclipse;
183185
SolarEclipseDetails nE1 = ev.NextEclipse;
184-
SolarEclipseDetails lE2 = data.SolarEclispe.LastEclipse;
185-
SolarEclipseDetails nE2 = data.SolarEclispe.NextEclipse;
186+
SolarEclipseDetails lE2 = data.SolarEclipse.LastEclipse;
187+
SolarEclipseDetails nE2 = data.SolarEclipse.NextEclipse;
186188

187189
PropertyInfo[] properties = typeof(SolarEclipseDetails).GetProperties();
188190
foreach (PropertyInfo property in properties)
@@ -682,6 +684,57 @@ public void Solar_Coordinate_Accuracy_Local_Time_Check()
682684
Assert.AreEqual(lcZ.SubsolarLongitude, lcL.SubsolarLongitude, .0001, "Subsolar Longitude");
683685
Assert.AreEqual(lcZ.RightAscension, lcL.RightAscension, .0000001, "Right Ascension");
684686
}
687+
/// <summary>
688+
/// Ensures day and night time spans are calculating correctly
689+
/// </summary>
690+
[TestMethod]
691+
public void Check_DayNight_Times()
692+
{
693+
//Rise and set at Z
694+
Coordinate c = new Coordinate(45, 112, new DateTime(2024, 9, 30));
695+
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
696+
697+
//Rise and set at local
698+
Coordinate c2 = new Coordinate(45, 112, new DateTime(2024, 9, 30));
699+
for (int i = -12; i <=14; i++)
700+
{
701+
c2.Offset = i;
702+
Assert.AreEqual(c.CelestialInfo.DaySpan.TotalMinutes, c2.CelestialInfo.DaySpan.TotalMinutes ,3.2); //3.2 minute delta accounts for day shift. Still accurate as long as sum of span = 24hrs
703+
Assert.AreEqual(new TimeSpan(24, 0, 0), c2.CelestialInfo.DaySpan + c2.CelestialInfo.NightSpan);
704+
Assert.AreEqual(new TimeSpan(11, 45, 0).TotalMinutes, c2.CelestialInfo.DaySpan.TotalMinutes, 3.8); //3.8 minute delta accounts for local day shift. Still accurate as long as sum of span = 24hrs
705+
Assert.AreEqual(new TimeSpan(12, 15, 0).TotalMinutes, c2.CelestialInfo.NightSpan.TotalMinutes, 3.8); //3.8 minute delta accounts for local day shift. Still accurate as long as sum of span = 24hrs
706+
if (c2.CelestialInfo.SunRise < c2.CelestialInfo.SunSet)
707+
{
708+
Assert.AreEqual(c2.CelestialInfo.DaySpan, c2.CelestialInfo.SunSet - c2.CelestialInfo.SunRise); //Checks timespan is calculating correctly
709+
}
710+
else
711+
{
712+
713+
Assert.AreEqual(c2.CelestialInfo.NightSpan, c2.CelestialInfo.SunRise - c2.CelestialInfo.SunSet); //Checks timespan is calculating correctly
714+
}
715+
}
716+
717+
718+
//Up all day
719+
c = new Coordinate(89, 112, new DateTime(2024, 12, 12));
720+
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
721+
Assert.AreEqual(new TimeSpan(0, 0, 0), c.CelestialInfo.DaySpan);
722+
723+
//Down all day
724+
c = new Coordinate(89, 112, new DateTime(2024, 6, 21));
725+
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
726+
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan);
727+
728+
//No Rise
729+
c = new Coordinate(76, 45, new DateTime(2021, 4, 24));
730+
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
731+
Assert.AreEqual(c.CelestialInfo.SunSet.Value.TimeOfDay, c.CelestialInfo.DaySpan);
732+
733+
//Down all day
734+
c = new Coordinate(-76, 45, new DateTime(2021, 2, 13));
735+
Assert.AreEqual(new TimeSpan(24, 0, 0), c.CelestialInfo.DaySpan + c.CelestialInfo.NightSpan);
736+
Assert.AreEqual(c.CelestialInfo.SunRise.Value.TimeOfDay, c.CelestialInfo.NightSpan);
737+
}
685738
}
686739

687740

@@ -703,7 +756,7 @@ public class Solar_Data
703756
public List<double> SunAlts { get; set; }
704757
public List<double> SunAzs { get; set; }
705758

706-
public SolarEclipse SolarEclispe { get; set; }
759+
public SolarEclipse SolarEclipse { get; set; }
707760

708761
public List<bool> IsSunUp { get; set; }
709762

0 commit comments

Comments
 (0)