Kstars

kstarsdatetime.h
1/*
2 SPDX-FileCopyrightText: 2001 Jason Harris <jharris@30doradus.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <QDateTime>
10
11#define J2000 2451545.0 //Julian Date for noon on Jan 1, 2000 (epoch J2000)
12#define B1950 2433282.4235 // Julian date for Jan 0.9235, 1950
13#define SIDEREALSECOND 1.002737909 //number of sidereal seconds in one solar second
14
15class dms;
16
17/** @class KStarsDateTime
18 *@short Extension of QDateTime for KStars
19 *KStarsDateTime can represent the date/time as a Julian Day, using a long double,
20 *in which the fractional portion encodes the time of day to a precision of a less than a second.
21 *Also adds Greenwich Sidereal Time and "epoch", which is just the date expressed as a floating
22 *point number representing the year, with the fractional part representing the date and time
23 *(with poor time resolution; typically the Epoch is only taken to the hundredths place, which is
24 *a few days).
25 *@note Local time and Local sideral time are not handled here. Because they depend on the
26 *geographic location, they are part of the GeoLocation class.
27 *@note The default timespec is UTC unless the passed value has different timespec value.
28 *@sa GeoLocation::GSTtoLST()
29 *@sa GeoLocation::UTtoLT()
30 *@author Jason Harris
31 *@author Jasem Mutlaq
32 *@version 1.1
33 */
34
36{
37 public:
38 /**
39 *@short Default constructor
40 *Creates a date/time at J2000 (noon on Jan 1, 200)
41 *@note This sets the timespec to UTC.
42 */
44
45 /**
46 *@short Constructor
47 *Creates a date/time at the specified Julian Day.
48 *@p jd The Julian Day
49 *@note This sets the timespec to UTC.
50 */
51 explicit KStarsDateTime(long double djd);
52
53 /**
54 *@short Copy constructor
55 *@p kdt The KStarsDateTime object to copy.
56 *@note The timespec is copied from kdt.
57 */
58 /** @{ */
60 KStarsDateTime &operator=(const KStarsDateTime &kdt) noexcept;
61 /** @} */
62
63 /**
64 *@short Copy constructor
65 *@p qdt The QDateTime object to copy.
66 *@note The timespec is copied from qdt.
67 */
68 explicit KStarsDateTime(const QDateTime &qdt);
69
70 /**
71 *@short Constructor
72 *Create a KStarsDateTimne based on the specified Date and Time.
73 *@p _d The QDate to assign
74 *@p _t The QTime to assign
75 *@p timespec The desired timespec, UTC by default.
76 */
77 KStarsDateTime(const QDate &_d, const QTime &_t, Qt::TimeSpec timeSpec = Qt::UTC);
78
79 /**
80 *Assign the static_cast<long double> Julian Day value, which includes the time of day
81 *encoded in the fractional portion.
82 *@p jd the Julian Day value to assign.
83 */
84 void setDJD(long double jd);
85
86 /**
87 *Assign the Date according to a QDate object.
88 *@p d the QDate to assign
89 */
90 void setDate(const QDate &d);
91
92 /**
93 *Assign the Time according to a QTime object.
94 *@p t the QTime to assign
95 *@note timespec is NOT changed even if the passed QTime has a different timespec than current.
96 */
97 void setTime(const QTime &t);
98
99 /**
100 *@return a KStarsDateTime that is the given number of seconds later
101 *than this KStarsDateTime.
102 *@p s the number of seconds to add. The number can be negative.
103 */
104 KStarsDateTime addSecs(double s) const;
105
106 /**
107 *Modify the Date/Time by adding a number of days.
108 *@p nd the number of days to add. The number can be negative.
109 */
110 inline KStarsDateTime addDays(int nd) const
111 {
112 KStarsDateTime kdt(djd() + static_cast<long double>(nd));
113 kdt.setTimeSpec(timeSpec());
114 return kdt;
115 }
116
117 inline bool operator==(const KStarsDateTime &d) const
118 {
119 return DJD == d.djd();
120 }
121 inline bool operator!=(const KStarsDateTime &d) const
122 {
123 return DJD != d.djd();
124 }
125 inline bool operator<(const KStarsDateTime &d) const
126 {
127 return DJD < d.djd();
128 }
129 inline bool operator<=(const KStarsDateTime &d) const
130 {
131 return DJD <= d.djd();
132 }
133 inline bool operator>(const KStarsDateTime &d) const
134 {
135 return DJD > d.djd();
136 }
137 inline bool operator>=(const KStarsDateTime &d) const
138 {
139 return DJD >= d.djd();
140 }
141
142 /**
143 *@return the date and time according to the CPU clock
144 */
146
147 /**
148 *@return the UTC date and time according to the CPU clock
149 */
151
152 /**
153 *@return a KStarsDateTime object parsed from the given string.
154 *@note This function is format-agnostic; it will try several formats
155 *when parsing the string.
156 *@param s the string expressing the date/time to be parsed.
157 */
158 static KStarsDateTime fromString(const QString &s);
159
160 /**
161 *@return the julian day as a long double, including the time as the fractional portion.
162 */
163 inline long double djd() const
164 {
165 return DJD;
166 }
167
168 /**
169 *@return The Greenwich Sidereal Time
170 *The Greenwich sidereal time is the Right Ascension coordinate that is currently transiting
171 *the Prime Meridian at the Royal Observatory in Greenwich, UK (longitude=0.0)
172 */
173 dms gst() const;
174
175 /**
176 *Convert a given Greenwich Sidereal Time to Universal Time (=Greenwich Mean Time).
177 *@p GST the Greenwich Sidereal Time to convert to Universal Time.
178 */
179 QTime GSTtoUT(dms GST) const; // FIXME: Shouldn't this be static?
180
181 /**
182 *@enum EpochType description options
183 *@note After 1976, the IAU standard for epochs is Julian Years.
184 */
186 {
187 JULIAN, /**< Julian epoch (see http://scienceworld.wolfram.com/astronomy/JulianEpoch.html) */
188 BESSELIAN, /**< Besselian epoch (see http://scienceworld.wolfram.com/astronomy/BesselianEpoch.html) */
189 };
190
191 /**
192 *@return the (Julian) epoch value of the Date/Time.
193 *@short This is (approximately) the year expressed as a floating-point value
194 *@sa setFromEpoch()
195 *@note The definition of Julian Epoch used here comes from http://scienceworld.wolfram.com/astronomy/JulianEpoch.html
196 */
197 inline double epoch() const
198 {
199 return 2000.0 + (djd() - J2000) / 365.25;
200 }
201
202 /**
203 *Set the Date/Time from an epoch value, represented as a double.
204 *@p e the epoch value
205 *@sa epoch()
206 */
207 bool setFromEpoch(double e, EpochType type);
208
209 /**
210 *Set the Date/Time from an epoch value, represented as a string.
211 *@p e the epoch value
212 *@return true if date set successfully
213 *@sa epoch()
214 */
215 bool setFromEpoch(const QString &e);
216
217 /**
218 *Set the Date/Time from an epoch value, represented as a double.
219 *@p e the epoch value
220 *@note This method assumes that the epoch 1950.0 is Besselian, otherwise assumes that the epoch is a Julian epoch. This is provided for backward compatibility, and because custom catalogs may still use 1950.0 to mean B1950.0 despite the IAU standard for epochs being Julian.
221 *@sa epoch()
222 */
223 void setFromEpoch(double e);
224
225 /**
226 *@short Takes in an epoch and returns a Julian Date
227 *@return the Julian Date (date with fraction)
228 *@param epoch A floating-point year value specifying the Epoch
229 *@param type JULIAN or BESSELIAN depending on what convention the epoch is specified in
230 */
231 static long double epochToJd(double epoch, EpochType type = JULIAN);
232
233 /**
234 *@short Takes in a Julian Date and returns the corresponding epoch year in the given system
235 *@return the epoch as a floating-point year value
236 *@param jd Julian date
237 *@param type Epoch system (KStarsDateTime::JULIAN or KStarsDateTime::BESSELIAN)
238 */
239 static double jdToEpoch(long double jd, EpochType type = JULIAN);
240
241 /**
242 *@short Takes in a string and returns a Julian epoch
243 */
244 static double stringToEpoch(const QString &eName, bool &ok);
245
246 /**
247 * The following values were obtained from Eric Weisstein's world of science:
248 * http://scienceworld.wolfram.com/astronomy/BesselianEpoch.html
249 */
250 constexpr static const double B1900 = 2415020.31352; // Julian date of B1900 epoch
251 constexpr static const double JD_PER_BYEAR = 365.242198781; // Julian days in a Besselian year
252 private:
253 /**
254 *@return the Greenwich Sidereal Time at 0h UT on this object's Date
255 *@note used internally by gst() and GSTtoUT()
256 */
257 dms GSTat0hUT() const;
258
259 long double DJD { 0 };
260};
Extension of QDateTime for KStars KStarsDateTime can represent the date/time as a Julian Day,...
void setDJD(long double jd)
Assign the static_cast<long double> Julian Day value, which includes the time of day encoded in the f...
static double jdToEpoch(long double jd, EpochType type=JULIAN)
Takes in a Julian Date and returns the corresponding epoch year in the given system.
KStarsDateTime addDays(int nd) const
Modify the Date/Time by adding a number of days.
double epoch() const
This is (approximately) the year expressed as a floating-point value.
QTime GSTtoUT(dms GST) const
Convert a given Greenwich Sidereal Time to Universal Time (=Greenwich Mean Time).
static long double epochToJd(double epoch, EpochType type=JULIAN)
Takes in an epoch and returns a Julian Date.
KStarsDateTime addSecs(double s) const
EpochType
description options
@ BESSELIAN
Besselian epoch (see http://scienceworld.wolfram.com/astronomy/BesselianEpoch.html)
@ JULIAN
Julian epoch (see http://scienceworld.wolfram.com/astronomy/JulianEpoch.html)
static KStarsDateTime fromString(const QString &s)
bool setFromEpoch(double e, EpochType type)
Set the Date/Time from an epoch value, represented as a double.
void setDate(const QDate &d)
Assign the Date according to a QDate object.
static KStarsDateTime currentDateTimeUtc()
KStarsDateTime()
Default constructor Creates a date/time at J2000 (noon on Jan 1, 200)
static KStarsDateTime currentDateTime()
long double djd() const
void setTime(const QTime &t)
Assign the Time according to a QTime object.
static constexpr const double B1900
The following values were obtained from Eric Weisstein's world of science: http://scienceworld....
static double stringToEpoch(const QString &eName, bool &ok)
Takes in a string and returns a Julian epoch.
An angle, stored as degrees, but expressible in many ways.
Definition dms.h:38
void setTimeSpec(Qt::TimeSpec spec)
Qt::TimeSpec timeSpec() const const
TimeSpec
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.