Bank System
date.h
Go to the documentation of this file.
1#ifndef date_h
2#define date_h
3
4#include <iostream>
5#include "config.h"
6#include <QDate>
7
8using namespace std;
9
10// 建表: 辅助计算相对日期, 表示平年每个月1号到1月1号的天数
11const int DAYS_EACH_MONTH[]={0,31,59,90,120,151,181,212,243,273,304,334,365};
12
13// 建表: 辅助判断有效日期, 表示平年每个月的最大天数
14const int DAY_EACH_MONTH[]={31,28,31,30,31,30,31,31,30,31,30,31};
15
16// 日期类
17class Date
18{
19 int year;
20 int month=1;
21 int day;
22
23public:
24 // 构造函数
25 Date(int m_year,int m_month,int m_day);
26 Date();
27
28 // 按格式 XXXX-XX-XX 打印日期
29 void show();
30 // 按 XXXX/XX/XX 格式读取日期
31 static Date read();
32 // 获取年
33 int getYear()const;
34 // 获取月
35 int getMonth()const;
36 // 获取日
37 int getDay()const;
38 // judge if the date invalid
39 bool isValid();
40 // 闰年判断
41 bool isLeap(int m_year)const;
42 // 获取当月最大天数
43 int getMaxDay()const;
44 // 转化成相对日期
45 int date_trans()const;
46 // 计算与目标日期的天数差
47 int distance(const Date& m_date)const;
48 // 重载运算符 < 以实现日期的比较
49 bool operator < (const Date& m_date)const;
50 bool operator <= (const Date& m_date)const;
51 // set Date to QDate
52 void setDate(QDate &m_qdate);
53 // reset Date from QDate
54 void resetDate(QDate m_qdate);
55};
56
57
58#endif /* date.h */
Definition: date.h:18
int getDay() const
Definition: date.cpp:41
int getMonth() const
Definition: date.cpp:35
bool operator<(const Date &m_date) const
Definition: date.cpp:135
int year
Definition: date.h:19
Date()
Definition: date.cpp:11
int month
Definition: date.h:20
bool operator<=(const Date &m_date) const
Definition: date.cpp:145
int day
Definition: date.h:21
void setDate(QDate &m_qdate)
Definition: date.cpp:155
int getMaxDay() const
Definition: date.cpp:89
bool isValid()
Definition: date.cpp:46
int getYear() const
Definition: date.cpp:29
void resetDate(QDate m_qdate)
Definition: date.cpp:161
static Date read()
Definition: date.cpp:20
bool isLeap(int m_year) const
Definition: date.cpp:78
int distance(const Date &m_date) const
Definition: date.cpp:129
void show()
Definition: date.cpp:14
int date_trans() const
Definition: date.cpp:109
const int DAY_EACH_MONTH[]
Definition: date.h:14
const int DAYS_EACH_MONTH[]
Definition: date.h:11