-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.h
67 lines (54 loc) · 1.43 KB
/
date.h
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
#pragma once
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
const std::vector<int> days_in_the_month = { 31,29,31,30,31,30,31,31,30,31,30,31 };
// --- class Date -------------------------------------------------------------
class Date {
public:
Date() = default;
Date(const Date& other)
: day_(other.day_), month_(other.month_), year_(other.year_) {}
Date(int day, int month, int year)
: day_(day), month_(month), year_(year)
{
InvalidMonth();
InvalidDay();
}
Date(const std::string& date)
{
Parse(date);
}
Date& operator=(const Date& other);
Date& operator++();
Date operator++(int);
Date& operator--();
Date operator--(int);
void SetDay(int day)
{
day_ = day;
}
const int Day() const;
const int Month() const;
const int Year() const;
const double Days() const;
private:
void InvalidYear();
void InvalidMonth();
void InvalidDay();
int StringToInt(const std::string& s);
void Parse(const std::string& date);
private:
int day_ = 1;
int month_ = 1;
int year_ = 2000;
};
bool operator==(const Date& lhs, const Date& rhs);
bool operator!=(const Date& lhs, const Date& rhs);
bool operator<(const Date& lhs, const Date& rhs);
bool operator<=(const Date& lhs, const Date& rhs);
bool operator>(const Date& lhs, const Date& rhs);
bool operator>=(const Date& lhs, const Date& rhs);
std::ostream& operator<<(std::ostream& out, Date date);
double Difference(const Date& lhs, const Date& rhs);