CppEphem
CERunningDate.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * CERunningDate.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2017 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
22 #include <stdio.h>
23 
24 #include "CERunningDate.h"
25 
44 /**********************************************************************/
48  CEDate()
49 {
50  init_members();
51 }
52 
53 
54 /**********************************************************************/
60  CEDate(other)
61 {
62  init_members();
63  copy_members(other);
64 }
65 
66 
67 /**********************************************************************/
71 {
72  free_members();
73 }
74 
75 
76 /**********************************************************************/
82 {
83  if (this != &other) {
84  this->CEDate::operator=(other);
85  free_members();
86  init_members();
87  copy_members(other);
88  }
89  return *this;
90 }
91 
92 /**********************************************************************/
97 double CERunningDate::JD() const
98 {
99  // Get the current Julian date
100  return CEDate::JD() + (ScaledRunTime()/86400.0) ;
101 }
102 
103 /**********************************************************************/
108 double CERunningDate::MJD() const
109 {
110  return CEDate::JD2MJD( this->JD() ) ;
111 }
112 
113 /**********************************************************************/
118 double CERunningDate::Gregorian() const
119 {
120  return CEDate::JD2Gregorian( this->JD() ) ;
121 }
122 
123 
124 /**********************************************************************/
127 double CERunningDate::RunTime() const
128 {
129  // Get the current system time in nanoseconds
130  std::chrono::nanoseconds cur_time(std::chrono::high_resolution_clock::now().time_since_epoch());
131  std::chrono::nanoseconds start_time(start_.time_since_epoch());
132 
133  // Return the difference in seconds
134  return (cur_time.count() - start_time.count())/1000000000.0;
135 }
136 
137 
138 //-------------------------------------------------
139 // PRIVATE METHODS
140 //-------------------------------------------------
141 
142 
143 /**********************************************************************/
149 {
150  start_ = other.start_;
152 }
153 
154 
155 /**********************************************************************/
159 {
160  start_ = std::chrono::high_resolution_clock::now();
161  timer_speed_factor_ = 1.0;
162 }
163 
164 
165 /**********************************************************************/
169 {
170  return;
171 }
CERunningDate
Definition: CERunningDate.h:29
CEPlanet::copy_members
void copy_members(const CEPlanet &other)
Copy data members from another CEPlanet object.
Definition: CEPlanet.cpp:913
CEDate
Definition: CEDate.h:43
CERunningDate::MJD
virtual double MJD() const
Get the current modified Julian date.
Definition: CERunningDate.cpp:107
CERunningDate::CERunningDate
CERunningDate()
Default constructor.
Definition: CERunningDate.cpp:46
CERunningDate::free_members
void free_members(void)
Deallocate data members.
Definition: CERunningDate.cpp:167
CERunningDate::Gregorian
virtual double Gregorian() const
Get the current Gregorian calendar date formatted as YYYYMMDD.D.
Definition: CERunningDate.cpp:117
CERunningDate::RunTime
virtual double RunTime(void) const
Method for getting the number of seconds since this object was created or reset.
Definition: CERunningDate.cpp:126
CERunningDate::init_members
void init_members(void)
Initialize data members.
Definition: CERunningDate.cpp:157
CERunningDate::~CERunningDate
virtual ~CERunningDate()
Destructor.
Definition: CERunningDate.cpp:69
CERunningDate::ScaledRunTime
double ScaledRunTime(void) const
Return the scaled ellapsed time since this object was created.
Definition: CERunningDate.h:103
CERunningDate::copy_members
void copy_members(const CERunningDate &other)
Copy data members from another object.
Definition: CERunningDate.cpp:147
CERunningDate.h
CERunningDate::operator=
CERunningDate & operator=(const CERunningDate &other)
Copy assignment operator.
Definition: CERunningDate.cpp:80
CEDate::JD2Gregorian
static double JD2Gregorian(const double jd)
Julian date -> Gregorian calendar date conversion method.
Definition: CEDate.cpp:193
CERunningDate::timer_speed_factor_
double timer_speed_factor_
Variable that can be used to speed up, slow down, or reverse the rate of time.
Definition: CERunningDate.h:79
CEPlanet::init_members
void init_members(void)
Initialize data members.
Definition: CEPlanet.cpp:974
CEDate::operator=
CEDate & operator=(const CEDate &other)
Copy assignent operator.
Definition: CEDate.cpp:90
CERunningDate::start_
std::chrono::high_resolution_clock::time_point start_
Variable to hold the starting time.
Definition: CERunningDate.h:76
CEDate::JD
virtual double JD() const
Get the Julian date represented by this object.
Definition: CEDate.h:150
CERunningDate::JD
virtual double JD() const
Get the current Julian date.
Definition: CERunningDate.cpp:96
CEDate::JD2MJD
static double JD2MJD(double jd)
Julian date -> modified Julian date conversion method.
Definition: CEDate.cpp:182