-
Notifications
You must be signed in to change notification settings - Fork 0
/
date.h
83 lines (66 loc) · 1.78 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <fstream>
class Date
{
public:
/**
Defaults Date to Epoch (1970/01/01)
*/
Date();
/**
WARNING: Does not check if crated Date is valid!
*/
Date(unsigned int aYear, unsigned int aMonth, unsigned int aDay);
/**
If the string is in a wrong format, it will set Date to an invalid state
(y = 0, m = 0, d = 0)
isValid will be false if the string was poorly constructed or if the Date read was invalid
*/
Date(const std::string& s, bool & isValid);
// GETTERS
unsigned int getDay() const;
unsigned int getMonth() const;
unsigned int getYear() const;
// OTHER PUBLIC METHODS
/**
Returns a Date object with the current system date
May only work in visual studio, requires additional testing
*/
Date now();
/**
Reads a Date from user input
Guarentees a valid Date (returns true)
Ctrl + Z to abort input (returns false)
*/
bool readUserInput();
/**
Reads a Date from file
Returns false if the Date is invalid
Also reeturns false if ifstrean.eof() or ifstream.fail() are detected
*/
bool readFromFile(std::ifstream& file, unsigned int& lineTracker, std::string & error);
/**
Returns true if it's a leap year
*/
bool isLeapYear() const;
/**
Returns true if the Date object is valid
Checks days in months, month belonging [1, 12] and leap years
*/
bool isValid() const;
bool operator< (const Date& d) const;
bool operator>= (const Date& d) const;
bool operator> (const Date& d) const;
bool operator<= (const Date& d) const;
bool operator== (const Date& d) const;
bool operator!= (const Date& d) const;
private:
unsigned int day, month, year;
};
std::ostream& operator<< (std::ostream& stream, const Date& date);
#endif // DATE_H
// T1G02
// up201800170 Breno Accioly
// up201806516 Tiago Silva