1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
|
/*
* CJulianDate.cpp
*
* Created on: 02.02.2017
* Author: mnl
*/
#include "CJulianDate.h"
#include <cstdio>
//===============================================
// Ergänzen Sie Ihren Code am Ende dieser Datei!
//===============================================
CJulianDate::CJulianDate(long date) {
m_days = date;
}
CJulianDate::CJulianDate(int year, short month, short day) {
fromGregorianDate(year, month, day);
}
long CJulianDate::getJulianDate() const {
return m_days;
}
void CJulianDate::setJulianDate(long date) {
m_days = date;
}
void CJulianDate::toGregorianDate(int& year, short & month, short & day) const {
long i, j, k, l, n;
l = m_days + 68569;
n = 4 * l / 146097;
l = l - (146097 * n + 3) / 4;
i = 4000 * (l + 1) / 1461001;
l = l - 1461 * i / 4 + 31;
j = 80 * l / 2447;
k = l - 2447 * j / 80;
l = j / 11;
j = j + 2 - 12 * l;
i = 100 * (n - 49) + i + l;
year = i;
month = j;
day = k;
}
void CJulianDate::fromGregorianDate(int year, short month, short day) {
m_days = day - 32075 + 1461 * (year + 4800 + (month - 14) / 12) / 4
+ 367 * (month - 2 - (month - 14) / 12 * 12) / 12
- 3 * ((year + 4900 + (month - 14) / 12) / 100) / 4;
}
int CJulianDate::dayOfWeek() const {
return (m_days % 7) + 1;
}
std::string CJulianDate::dayOfWeekAsName() const {
switch (dayOfWeek()) {
case 1:
return "Montag";
case 2:
return "Dienstag";
case 3:
return "Mittwoch";
case 4:
return "Donnerstag";
case 5:
return "Freitag";
case 6:
return "Samstag";
case 7:
return "Sonntag";
default:
return "(Fehler)";
}
}
std::string CJulianDate::formatDayNumber(short day) const {
char buffer[5];
int year;
short month;
short refDay;
toGregorianDate(year, month, refDay);
sprintf(buffer, day == refDay ? "[%2d]" : " %2d ", day);
return std::string(buffer);
}
bool CJulianDate::operator <(const CJulianDate& rhs) const {
return m_days < rhs.m_days;
}
//=====================================================
// Ergänzen Sie Ihren Code unterhalb dieses Kommentars
//=====================================================
ostream& operator << (ostream& lop, const CJulianDate& rhs){
short day, month;
int year;
rhs.toGregorianDate(year, month, day);
lop<< rhs.dayOfWeekAsName() << ", " << day << "." << month << "." << year << std::endl;
return lop;
}
long operator-(const CJulianDate& other) {
return this.m_days - other.m_days;
}
|