Leap year time fix for satellite tracking

This commit is contained in:
GPayne
2020-04-19 23:47:30 -06:00
parent 0125fb7a3b
commit fbd5d3490a
2 changed files with 4 additions and 43 deletions

View File

@@ -60,7 +60,7 @@ namespace {
};
// Find the position of the current year in the vector; its position in
// the vector gives the number of leap seconds
// the vector gives the number of leap seconds
struct LeapSecond {
int year;
int dayOfYear;
@@ -246,9 +246,7 @@ double RenderableOrbitalKepler::epochFromSubstring(const std::string& epochStrin
// The main overview of this function:
// 1. Reconstruct the full year from the YY part
// 2. Calculate the number of seconds since the beginning of the year
// 2.a Get the number of full days since the beginning of the year
// 2.b If the year is a leap year, modify the number of days
// 2. Calculate the number of days since the beginning of the year
// 3. Convert the number of days to a number of seconds
// 4. Get the number of leap seconds since January 1st, 2000 and remove them
// 5. Adjust for the fact the epoch starts on 1st Januaray at 12:00:00, not
@@ -267,18 +265,8 @@ double RenderableOrbitalKepler::epochFromSubstring(const std::string& epochStrin
const int daysSince2000 = countDays(year);
// 2.
// 2.a
double daysInYear = std::atof(epochString.substr(2).c_str());
// 2.b
const bool isInLeapYear =
std::find(LeapYears.begin(), LeapYears.end(), year) != LeapYears.end();
if (isInLeapYear && daysInYear >= 60) {
// We are in a leap year, so we have an effective day more if we are
// beyond the end of february (= 31+29 days)
--daysInYear;
}
// 3
using namespace std::chrono;
const int SecondsPerDay = static_cast<int>(seconds(hours(24)).count());
@@ -309,9 +297,7 @@ double RenderableOrbitalKepler::epochFromYMDdSubstring(const std::string& epochS
// The main overview of this function:
// 1. Read the year value
// 2. Calculate the number of seconds since the beginning of the year
// 2.a Get the number of full days since the beginning of the year
// 2.b If the year is a leap year, modify the number of days
// 2. Calculate the number of days since the beginning of the year
// 3. Convert the number of days to a number of seconds
// 4. Get the number of leap seconds since January 1st, 2000 and remove them
// 5. Adjust for the fact the epoch starts on 1st January at 12:00:00, not
@@ -322,22 +308,12 @@ double RenderableOrbitalKepler::epochFromYMDdSubstring(const std::string& epochS
const int daysSince2000 = countDays(year);
// 2.
// 2.a
int monthNum = std::atoi(epochString.substr(4, 2).c_str());
int dayOfMonthNum = std::atoi(epochString.substr(6, 2).c_str());
int wholeDaysInto = daysIntoGivenYear(monthNum, dayOfMonthNum);
double fractionOfDay = std::atof(epochString.substr(9, 7).c_str());
double daysInYear = static_cast<double>(wholeDaysInto) + fractionOfDay;
// 2.b
const bool isInLeapYear =
std::find(LeapYears.begin(), LeapYears.end(), year) != LeapYears.end();
if (isInLeapYear && daysInYear >= 60) {
// We are in a leap year, so we have an effective day more if we are
// beyond the end of february (= 31+29 days)
--daysInYear;
}
// 3
using namespace std::chrono;
const int SecondsPerDay = static_cast<int>(seconds(hours(24)).count());

View File

@@ -145,9 +145,7 @@ namespace {
// The main overview of this function:
// 1. Reconstruct the full year from the YY part
// 2. Calculate the number of seconds since the beginning of the year
// 2.a Get the number of full days since the beginning of the year
// 2.b If the year is a leap year, modify the number of days
// 2. Calculate the number of days since the beginning of the year
// 3. Convert the number of days to a number of seconds
// 4. Get the number of leap seconds since January 1st, 2000 and remove them
// 5. Adjust for the fact the epoch starts on 1st Januaray at 12:00:00, not
@@ -168,21 +166,8 @@ namespace {
const int daysSince2000 = countDays(year);
// 2.
// 2.a
double daysInYear = std::atof(epochString.substr(2).c_str());
// 2.b
const bool isInLeapYear = std::find(
LeapYears.begin(),
LeapYears.end(),
year
) != LeapYears.end();
if (isInLeapYear && daysInYear >= 60) {
// We are in a leap year, so we have an effective day more if we are
// beyond the end of february (= 31+29 days)
--daysInYear;
}
// 3
using namespace std::chrono;
const int SecondsPerDay = static_cast<int>(seconds(hours(24)).count());