This repository has been archived by the owner on Nov 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
julian.cpp
71 lines (63 loc) · 1.74 KB
/
julian.cpp
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
#include <ctime>
#include "julian.hpp"
#include "date.hpp"
#include "gregorian.hpp"
#include <stdexcept>
#define KATTIS (0)
#if KATTIS
#include "kattistime.h"
#endif
namespace lab2 {
Julian::Julian(int y, int m, int d) : Date(y, m, d) {
if (mYear < 1858 || mYear> 2558) {
throw std::out_of_range("Bad year");
}
if (mMonth < 1 || mMonth > 12) {
throw std::invalid_argument("Bad month");
}
if (mDay < 1) {
throw std::invalid_argument("Bad day");
}
int test = days_this_month();
if (mDay > test) throw std::invalid_argument("Bad day");
}
// Create a Julian calendar with the current date.
Julian::Julian() {
#if KATTIS
// kattis time include "kattistime.h"
time_t mytime;
k_time(&mytime);
struct tm *now = gmtime(&mytime);
#else
// local time
time_t ms = time(0);
struct tm *now = gmtime(&ms);
#endif
// Convert to Gregorian calendar format
mYear = now->tm_year + 1900;
mMonth = now->tm_mon + 1;
mDay = now->tm_mday;
// Convert gregorian to this object
convert(G);
}
Julian::Julian(const Date &d) {
if (d.type() == G) {
mYear = d.year();
mMonth = d.month();
mDay = d.day();
convert(d.type());
}
}
// -------------------- Virtual operators/functions ------------------
Julian& Julian::operator=(const Date& d) {
std::cout << "Julian = " << std::endl;
if (d.type() == G) {
mYear = d.year();
mMonth = d.month();
mDay = d.day();
convert(d.type());
}
return *this;
}
Type Julian::type() const { return Type(J); }
}