1 /*
2  * Copyright (C) 2020 Georg Zotti
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
17  */
18 
19 #ifndef JULIANCALENDAR_HPP
20 #define JULIANCALENDAR_HPP
21 
22 #include "Calendar.hpp"
23 
24 //! Stellarium uses Julian Day numbers internally, and the conventional approach of using the Gregorian calendar for dates after 1582-10-15.
25 //! For dates before that, the Julian calendar is used, in the form finalized by Augustus and running unchanged since 8AD.
26 //! Some European countries, especially the Protestant countries, delayed the calendar switch well into the 18th century.
27 //! @note The implementation does not correctly represent the Roman Julian calendar valid from introduction by Julius Caesar to the reform by Augustus.
28 //! @note this implementation adheres to Calendrical Calculation's style of omitting a year zero. Negative years represent years B.C.E.
29 //!       This is very much in contrast to Stellarium's usual behaviour, and also different from a year zero in CC's implementation of the Gregorian calendar.
30 
31 class JulianCalendar : public Calendar
32 {
33 	Q_OBJECT
34 
35 public:
36 	typedef enum {january=1, february, march, april, may, june, july, august, september, october, november, december } month;
37 
38 	JulianCalendar(double jd);
39 
~JulianCalendar()40 	virtual ~JulianCalendar() Q_DECL_OVERRIDE {}
41 
42 public slots:
43 	virtual void retranslate() Q_DECL_OVERRIDE;
44 
45 	//! Set a calendar date from the Julian day number
46 	virtual void setJD(double JD) Q_DECL_OVERRIDE;
47 
48 	//! set date from a vector of calendar date elements sorted from the largest to the smallest.
49 	//! Year-Month[1...12]-Day[1...31]
50 	virtual void setDate(QVector<int> parts) Q_DECL_OVERRIDE;
51 
52 	//! get a stringlist of calendar date elements sorted from the largest to the smallest.
53 	//! Year, Month, MonthName, Day, DayName
54 	virtual QStringList getDateStrings() const Q_DECL_OVERRIDE;
55 
56 	//! get a formatted complete string for a date
57 	virtual QString getFormattedDateString() const Q_DECL_OVERRIDE;
58 
59 public:
60 	//! return name of week day. This is actually independent from any calendar, just a modulo of JD.
61 	static QString weekday(double jd);
62 
63 	//! returns true for leap years
64 	static bool isLeap(int year);
65 
66 	//! find RD number for date in the Julian calendar (may be used in other calendars!)
67 	static int fixedFromJulian(QVector<int> julian);
68 	//! find date in the Julian calendar from RD number (may be used in other calendars!)
69 	static QVector<int> julianFromFixed(int rd);
70 
71 	constexpr static const int julianEpoch=-1; //! RD of January 1, AD1.
72 
73 protected:
74 	static QMap<int, QString> weekDayNames;
75 	static QMap<int, QString> monthNames;
76 };
77 
78 #endif
79