Practical Astronomy Algorithms in .NET/C#
Loading...
Searching...
No Matches
PADateTime.cs
Go to the documentation of this file.
1using System;
2using PALib.Helpers;
3
4namespace PALib;
5
9public class PADateTime
10{
15 public (int Month, int Day, int Year) GetDateOfEaster(int inputYear)
16 {
17 double year = inputYear;
18
19 double a = year % 19;
20 double b = (year / 100).Floor();
21 double c = year % 100;
22 double d = (b / 4).Floor();
23 double e = b % 4;
24 double f = ((b + 8) / 25).Floor();
25 double g = ((b - f + 1) / 3).Floor();
26 double h = ((19 * a) + b - d - g + 15) % 30;
27 double i = (c / 4).Floor();
28 double k = c % 4;
29 double l = (32 + 2 * (e + i) - h - k) % 7;
30 double m = ((a + (11 * h) + (22 * l)) / 451).Floor();
31 double n = ((h + l - (7 * m) + 114) / 31).Floor();
32 double p = (h + l - (7 * m) + 114) % 31;
33
34 double day = p + 1;
35 double month = n;
36
37 return ((int)month, (int)day, (int)year);
38 }
39
43 public int CivilDateToDayNumber(int month, int day, int year)
44 {
45 if (month <= 2)
46 {
47 month--;
48 month = year.IsLeapYear() ? month * 62 : month * 63;
49 month = (int)((double)month / 2).Floor();
50 }
51 else
52 {
53 month = (int)(((double)month + 1) * 30.6).Floor();
54 month = year.IsLeapYear() ? month - 62 : month - 63;
55 }
56
57 return month + day;
58 }
59
63 public double CivilTimeToDecimalHours(double hours, double minutes, double seconds)
64 {
65 return PAMacros.HMStoDH(hours, minutes, seconds);
66 }
67
72 public (double hours, double minutes, double seconds) DecimalHoursToCivilTime(double decimalHours)
73 {
74 int hours = PAMacros.DecimalHoursHour(decimalHours);
75 int minutes = PAMacros.DecimalHoursMinute(decimalHours);
76 double seconds = PAMacros.DecimalHoursSecond(decimalHours);
77
78 return (hours, minutes, seconds);
79 }
80
85 public (int utHours, int utMinutes, int utSeconds, int gwDay, int gwMonth, int gwYear) LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSavings, int zoneCorrection, double localDay, int localMonth, int localYear)
86 {
88
89 int daylightSavingsOffset = isDaylightSavings ? 1 : 0;
90
91 double utInterim = lct - daylightSavingsOffset - zoneCorrection;
92 double gdayInterim = localDay + (utInterim / 24);
93
94 double jd = PAMacros.CivilDateToJulianDate(gdayInterim, localMonth, localYear);
95
96 double gDay = PAMacros.JulianDateDay(jd);
97 int gMonth = PAMacros.JulianDateMonth(jd);
98 int gYear = PAMacros.JulianDateYear(jd);
99
100 double ut = 24 * (gDay - gDay.Floor());
101
102 return (
106 (int)gDay.Floor(),
107 gMonth,
108 gYear
109 );
110 }
111
116 public (int lctHours, int lctMinutes, int lctSeconds, int localDay, int localMonth, int localYear) UniversalTimeToLocalCivilTime(double utHours, double utMinutes, double utSeconds, bool isDaylightSavings, int zoneCorrection, int gwDay, int gwMonth, int gwYear)
117 {
118 int dstValue = isDaylightSavings ? 1 : 0;
120 double zoneTime = ut + zoneCorrection;
121 double localTime = zoneTime + dstValue;
122 double localJDPlusLocalTime = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear) + (localTime / 24);
123 double localDay = PAMacros.JulianDateDay(localJDPlusLocalTime);
124 double integerDay = localDay.Floor();
125 int localMonth = PAMacros.JulianDateMonth(localJDPlusLocalTime);
126 int localYear = PAMacros.JulianDateYear(localJDPlusLocalTime);
127
128 double lct = 24 * (localDay - integerDay);
129
130 return (
134 (int)integerDay,
136 localYear
137 );
138 }
139
144 public (int gstHours, int gstMinutes, double gstSeconds) UniversalTimeToGreenwichSiderealTime(double utHours, double utMinutes, double utSeconds, double gwDay, int gwMonth, int gwYear)
145 {
146 double jd = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear);
147 double s = jd - 2451545;
148 double t = s / 36525;
149 double t01 = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t);
150 double t02 = t01 - (24.0 * (t01 / 24).Floor());
152 double a = ut * 1.002737909;
153 double gst1 = t02 + a;
154 double gst2 = gst1 - (24.0 * (gst1 / 24).Floor());
155
158 double gstSeconds = PAMacros.DecimalHoursSecond(gst2);
159
160 return (gstHours, gstMinutes, gstSeconds);
161 }
162
167 public (int utHours, int utMinutes, double utSeconds, PAWarningFlag warningFlag) GreenwichSiderealTimeToUniversalTime(double gstHours, double gstMinutes, double gstSeconds, double gwDay, int gwMonth, int gwYear)
168 {
169 double jd = PAMacros.CivilDateToJulianDate(gwDay, gwMonth, gwYear);
170 double s = jd - 2451545;
171 double t = s / 36525;
172 double t01 = 6.697374558 + (2400.051336 * t) + (0.000025862 * t * t);
173 double t02 = t01 - (24 * (t01 / 24).Floor());
174 double gstHours1 = PAMacros.HMStoDH(gstHours, gstMinutes, gstSeconds);
175
176 double a = gstHours1 - t02;
177 double b = a - (24 * (a / 24).Floor());
178 double ut = b * 0.9972695663;
182
183 PAWarningFlag warningFlag = (ut < 0.065574) ? PAWarningFlag.Warning : PAWarningFlag.OK;
184
185 return (utHours, utMinutes, utSeconds, warningFlag);
186 }
187
192 public (int lstHours, int lstMinutes, double lstSeconds) GreenwichSiderealTimeToLocalSiderealTime(double gstHours, double gstMinutes, double gstSeconds, double geographicalLongitude)
193 {
194 double gst = PAMacros.HMStoDH(gstHours, gstMinutes, gstSeconds);
195 double offset = geographicalLongitude / 15;
196 double lstHours1 = gst + offset;
197 double lstHours2 = lstHours1 - (24 * (lstHours1 / 24).Floor());
198
199 int lstHours = PAMacros.DecimalHoursHour(lstHours2);
200 int lstMinutes = PAMacros.DecimalHoursMinute(lstHours2);
201 double lstSeconds = PAMacros.DecimalHoursSecond(lstHours2);
202
203 return (lstHours, lstMinutes, lstSeconds);
204 }
205
210 public (int gstHours, int gstMinutes, double gstSeconds) LocalSiderealTimeToGreenwichSiderealTime(double lstHours, double lstMinutes, double lstSeconds, double geographicalLongitude)
211 {
212 double gst = PAMacros.HMStoDH(lstHours, lstMinutes, lstSeconds);
213 double longHours = geographicalLongitude / 15;
214 double gst1 = gst - longHours;
215 double gst2 = gst1 - (24 * (gst1 / 24).Floor());
216
219 double gstSeconds = PAMacros.DecimalHoursSecond(gst2);
220
221 return (gstHours, gstMinutes, gstSeconds);
222 }
223}
Date and time calculations.
Definition PADateTime.cs:10
int int double PAWarningFlag warningFlag GreenwichSiderealTimeToUniversalTime(double gstHours, double gstMinutes, double gstSeconds, double gwDay, int gwMonth, int gwYear)
int int int Year GetDateOfEaster(int inputYear)
Definition PADateTime.cs:15
int gstHours
Convert Universal Time to Greenwich Sidereal Time.
double CivilTimeToDecimalHours(double hours, double minutes, double seconds)
Convert a Civil Time (hours,minutes,seconds) to Decimal Hours.
Definition PADateTime.cs:63
int int double lstSeconds GreenwichSiderealTimeToLocalSiderealTime(double gstHours, double gstMinutes, double gstSeconds, double geographicalLongitude)
int lctHours
Convert Universal Time to local Civil Time.
double double double seconds DecimalHoursToCivilTime(double decimalHours)
Definition PADateTime.cs:72
int utHours
Convert local Civil Time to Universal Time.
Definition PADateTime.cs:85
int int int int int int localYear UniversalTimeToLocalCivilTime(double utHours, double utMinutes, double utSeconds, bool isDaylightSavings, int zoneCorrection, int gwDay, int gwMonth, int gwYear)
int Month
Gets the date of Easter for the year specified.
Definition PADateTime.cs:15
int int double gstSeconds LocalSiderealTimeToGreenwichSiderealTime(double lstHours, double lstMinutes, double lstSeconds, double geographicalLongitude)
int int int int gwDay
Definition PADateTime.cs:85
int int int int int gwMonth
Definition PADateTime.cs:85
double double minutes
Definition PADateTime.cs:72
int int utMinutes
Definition PADateTime.cs:85
int int int int localDay
int int int int int int gwYear LocalCivilTimeToUniversalTime(double lctHours, double lctMinutes, double lctSeconds, bool isDaylightSavings, int zoneCorrection, double localDay, int localMonth, int localYear)
Definition PADateTime.cs:85
int int int int int localMonth
int int double gstSeconds UniversalTimeToGreenwichSiderealTime(double utHours, double utMinutes, double utSeconds, double gwDay, int gwMonth, int gwYear)
int int int utSeconds
Definition PADateTime.cs:85
int int int lctSeconds
double hours
Convert Decimal Hours to Civil Time.
Definition PADateTime.cs:72
int CivilDateToDayNumber(int month, int day, int year)
Calculate day number for a date.
Definition PADateTime.cs:43
int lstHours
Convert Greenwich Sidereal Time to Local Sidereal Time.
Miscellaneous macro functions supporting the other classes.
Definition PAMacros.cs:13
static double CivilDateToJulianDate(double day, double month, double year)
Convert a Greenwich Date/Civil Date (day,month,year) to Julian Date.
Definition PAMacros.cs:87
static double JulianDateDay(double julianDate)
Returns the day part of a Julian Date.
Definition PAMacros.cs:134
static int DecimalHoursMinute(double decimalHours)
Return the minutes part of a Decimal Hours.
Definition PAMacros.cs:55
static double DecimalHoursSecond(double decimalHours)
Return the seconds part of a Decimal Hours.
Definition PAMacros.cs:71
static int JulianDateMonth(double julianDate)
Returns the month part of a Julian Date.
Definition PAMacros.cs:154
static int DecimalHoursHour(double decimalHours)
Return the hour part of a Decimal Hours.
Definition PAMacros.cs:39
static int JulianDateYear(double julianDate)
Returns the year part of a Julian Date.
Definition PAMacros.cs:175
static double HMStoDH(double hours, double minutes, double seconds)
Convert a Civil Time (hours,minutes,seconds) to Decimal Hours.
Definition PAMacros.cs:20
PAWarningFlag
Warning flags for calculation results.
Definition PATypes.cs:81