Skip to content

Commit 8a51959

Browse files
author
reed
committed
Fixed buf in adding ticks to Epoch
1 parent a61afea commit 8a51959

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

One_Sgp4/One_Sgp4.csproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
4+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
55
<Authors>Reed</Authors>
66
<Company>1 Man Projects</Company>
77
<Description>This library calculates the orbits of satellites via TLEs data from the web. Other functions for coordination transformation, time calculations and the calculation of contact windows depending on the observers coordinates on earth are also available.</Description>
@@ -20,11 +20,14 @@
2020
<PropertyGroup>
2121
<TargetFrameworks>netstandard2.1;netstandard2.0;net40;net45</TargetFrameworks>
2222
<Version>1.0.11</Version>
23-
<PackageReleaseNotes>Included Net 4.0 and Net 4.5 as TargetFrameworks</PackageReleaseNotes>
23+
<PackageReleaseNotes>Fixed minor conversion Issues with Date time</PackageReleaseNotes>
2424
<AssemblyVersion>1.0.11.0</AssemblyVersion>
2525
<PackageLicenseExpression />
2626
<PackageLicenseFile>license.txt</PackageLicenseFile>
2727
<FileVersion>1.0.11.0</FileVersion>
28+
<Product>One_Sgp4</Product>
29+
<PackageId>One_Sgp4</PackageId>
30+
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
2831
</PropertyGroup>
2932

3033
<ItemGroup>

One_Sgp4/ground/Pass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public PassDetail getPassDetailOfMaxElevation()
9999
*/
100100
public override string ToString()
101101
{
102-
return string.Format("{0}:\nStart: {1}\nMax Elevation: {2}\nEnd: {3}", start.time.getDateToString(), start.ToString(), maxElevation.ToString(), end.ToString());
102+
return string.Format("{0}:\nStart: {1}\nMax Elevation: {2}\nEnd: {3}", start.time.ToString(), start.ToString(), maxElevation.ToString(), end.ToString());
103103
}
104104
}
105105
}

One_Sgp4/time/EpochTime.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class EpochTime : IComparable<EpochTime>
4040
private double epoch; //!< double epoch of the Date
4141

4242
private const double secToDay = 86400.0; //!< double constant seconds of a day
43-
private int days = 365; //!< int days in the year
43+
private const int days = 365; //!< int days in the year
4444

4545
private const double twoPi = 2.0 * Math.PI; //!< double constant two Pi
4646
public const double toRadians = Math.PI / 180.0; //!< double constant converstion to radians
@@ -216,7 +216,7 @@ public override string ToString()
216216
time = (time - hour) * 60.0;
217217
int min = Convert.ToInt32(Math.Floor(time));
218218
int sec = Convert.ToInt32 ((time - min) * 60.0 );
219-
string date = getDay() + "." + getMonth().ToString("00") + "." + getYear() + "-" + hour.ToString("00") + ":" +
219+
string date = getDay().ToString("00") + "." + getMonth().ToString("00") + "." + getYear() + "-" + hour.ToString("00") + ":" +
220220
min.ToString("00") + ":" +
221221
sec.ToString("00");
222222
return date;
@@ -241,6 +241,10 @@ private void dayToDate(int year, double epoch)
241241
year = year + 1900;
242242
}
243243
int dayOfYear = Convert.ToInt32(Math.Floor(epoch));
244+
if (dayOfYear == 0)
245+
{
246+
dayOfYear = 1;
247+
}
244248

245249
int[] months = new int[12] {31,28,31,30,31,30,31,31,30,31,30,31};
246250
if( year % 4 == 0)
@@ -278,6 +282,7 @@ private void convertEpochToTime()
278282
time = (time - hour) * 60.0;
279283
minutes = Convert.ToInt32(Math.Floor(time));
280284
seconds = (time - minutes) * 60.0;
285+
dayToDate(this.year, this.epoch);
281286
}
282287

283288
//! adds an tick in seconds on current time
@@ -290,17 +295,15 @@ private void convertEpochToTime()
290295
public void addTick(double tick)
291296
{
292297
epoch = epoch + (tick / secToDay );
298+
int daysInYear = days;
293299
if (year % 4 == 0)
294300
{
295-
days = 366;
296-
}
297-
else
298-
{
299-
days = 365;
301+
daysInYear = days + 1;
300302
}
301-
if(epoch >= days + 1)
303+
if(epoch >= daysInYear + 1)
302304
{
303-
epoch = epoch % 1;
305+
epoch = epoch - daysInYear;
306+
//epoch = epoch % 1;
304307
year++;
305308
}
306309
convertEpochToTime();
@@ -490,8 +493,7 @@ public override bool Equals(object obj)
490493
year == time.year &&
491494
month == time.month &&
492495
day == time.day &&
493-
epoch == time.epoch &&
494-
days == time.days;
496+
epoch == time.epoch;
495497
}
496498

497499
//! GetHaschCode Operator

Test/EpochTimeTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,17 @@ public void TestJulianDate(int yyyy, int MM, int dd, int hh, int mm, int ss, dou
9797
double etJul = et.toJulianDate();
9898
Assert.That(etJul, Is.InRange(julianDate-e,julianDate+e));
9999
}
100+
101+
102+
[TestCase(1999,4,22,12,45,30, 3 * 86400.0, "25.04.1999-12:45:30")]
103+
[TestCase(1999, 12, 29, 12, 00, 00, 6 * 86400.0, "04.01.2000-12:00:00")]
104+
[TestCase(2020, 12, 29, 12, 00, 00, 6 * 86400.0, "04.01.2021-12:00:00")]
105+
[TestCase(2018, 11, 20, 05, 45, 33, 5 * 86400.0, "25.11.2018-05:45:33")]
106+
public void TestToString(int yyyy, int MM, int dd, int hh, int mm, int ss, double ticksToAdd, string result)
107+
{
108+
EpochTime epoch = new EpochTime(hh, mm, ss, yyyy, MM, dd);
109+
epoch.addTick(ticksToAdd);
110+
Assert.AreEqual(result, epoch.ToString());
111+
}
100112
}
101113
}

0 commit comments

Comments
 (0)