1 |
//
|
2 |
// cJulian.h
|
3 |
//
|
4 |
// Copyright (c) 2003 Michael F. Henry
|
5 |
//
|
6 |
#pragma once
|
7 |
#include "globals.h"
|
8 |
#include <time.h>
|
9 |
|
10 |
//
|
11 |
// See note in cJulian.cpp for information on this class and the epoch dates
|
12 |
//
|
13 |
const double EPOCH_JAN1_00H_1900 = 2415019.5; // Jan 1.0 1900 = Jan 1 1900 00h UTC
|
14 |
const double EPOCH_JAN1_12H_1900 = 2415020.0; // Jan 1.5 1900 = Jan 1 1900 12h UTC
|
15 |
const double EPOCH_JAN1_12H_2000 = 2451545.0; // Jan 1.5 2000 = Jan 1 2000 12h UTC
|
16 |
|
17 |
//////////////////////////////////////////////////////////////////////////////
|
18 |
class cJulian
|
19 |
{
|
20 |
public:
|
21 |
cJulian() { Initialize(2000, 1); }
|
22 |
explicit cJulian(time_t t); // Create from time_t
|
23 |
explicit cJulian(int year, double day); // Create from year, day of year
|
24 |
explicit cJulian(int year, // i.e., 2004
|
25 |
int mon, // 1..12
|
26 |
int day, // 1..31
|
27 |
int hour, // 0..23
|
28 |
int min, // 0..59
|
29 |
double sec = 0.0); // 0..(59.999999...)
|
30 |
~cJulian() {};
|
31 |
|
32 |
double toGMST() const; // Greenwich Mean Sidereal Time
|
33 |
double toLMST(double lon) const; // Local Mean Sideral Time
|
34 |
time_t toTime() const; // To time_t type - avoid using
|
35 |
|
36 |
double FromJan1_00h_1900() const { return m_Date - EPOCH_JAN1_00H_1900; }
|
37 |
double FromJan1_12h_1900() const { return m_Date - EPOCH_JAN1_12H_1900; }
|
38 |
double FromJan1_12h_2000() const { return m_Date - EPOCH_JAN1_12H_2000; }
|
39 |
|
40 |
void getComponent(int *pYear, int *pMon = NULL, double *pDOM = NULL) const;
|
41 |
double getDate() const { return m_Date; }
|
42 |
|
43 |
void addDay (double day) { m_Date += day; }
|
44 |
void addHour(double hr ) { m_Date += (hr / HR_PER_DAY ); }
|
45 |
void addMin (double min) { m_Date += (min / MIN_PER_DAY); }
|
46 |
void addSec (double sec) { m_Date += (sec / SEC_PER_DAY); }
|
47 |
|
48 |
double spanDay (const cJulian& b) const { return m_Date - b.m_Date; }
|
49 |
double spanHour(const cJulian& b) const { return spanDay(b) * HR_PER_DAY; }
|
50 |
double spanMin (const cJulian& b) const { return spanDay(b) * MIN_PER_DAY; }
|
51 |
double spanSec (const cJulian& b) const { return spanDay(b) * SEC_PER_DAY; }
|
52 |
|
53 |
static bool IsLeapYear(int y)
|
54 |
{ return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0); }
|
55 |
|
56 |
protected:
|
57 |
void Initialize(int year, double day);
|
58 |
|
59 |
double m_Date; // Julian date
|
60 |
};
|