Skip to content

Commit c236e1c

Browse files
committed
添加sxtwl的月干支与二十四节气关联
1 parent 4892763 commit c236e1c

File tree

6 files changed

+57
-16
lines changed

6 files changed

+57
-16
lines changed

.vscode/settings.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"files.autoSave": "onFocusChange",
3-
"editor.fontSize": 14,
4-
"editor.fontFamily": "'FiraCode Nerd Font Mono', 'FiraCode Nerd Font Mono', 'FiraCode Nerd Font Mono'",
3+
"editor.fontSize": 16,
4+
"editor.fontFamily": "'Operator Mono Lig', 'Operator Mono Lig', 'Operator Mono Lig'",
55
"cmake.configureOnOpen": true,
66
"cmake.debugConfig": {
77
"console": "integratedTerminal",
8-
"args": ["-t", "3", "-d", "9999-1-1-1-1-1"]
8+
"args": ["-t", "1", "-d", "1994-6-6-3-5-0"]
99
},
1010
"cmake.generator": "Ninja",
1111
"cmake.options.statusBarVisibility": "visible",

CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
66

77
if (MSVC)
88
add_compile_options(/source-charset:utf-8)
9-
add_compile_options(/wd4018) #有符号与无符号的比较 (主要作用与三方库)
9+
# 以下抑制,主要作用与三方库。
10+
add_compile_options(/wd4018) #有符号与无符号的比较
11+
add_compile_options(/wd4800) #将值强制为布尔值“true”或“false”(性能警告)
1012
endif()
1113

1214
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows")

box_calendar/calendar_base.cpp

+29-12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,20 @@ CDate& CDate::operator=(const CDate& date)
4343
return *this;
4444
}
4545

46+
bool CDate::operator!=(const CDate& date)
47+
{
48+
if (this->m_nYear != date.m_nYear) {
49+
return true;
50+
}
51+
if (this->m_nMon != date.m_nMon) {
52+
return true;
53+
}
54+
if (this->m_nDay != date.m_nDay) {
55+
return true;
56+
}
57+
return false;
58+
}
59+
4660
CDateTime::CDateTime(const CDate& rh)
4761
{
4862
m_date.m_nYear = rh.m_nYear;
@@ -90,22 +104,25 @@ CCalenderBase* CCalenderFactory::creatInstance(CalendarType etype)
90104
CCalenderBase* pResult = nullptr;
91105

92106
switch (etype) {
93-
case CALENDAR_V1: {
94-
pResult = new CCalenderV1();
95-
break;
96-
}
97-
case CALENDAR_V2: {
98-
pResult = new CCalenderV2();
99-
break;
100-
}
101-
default:
102-
break;
107+
case CALENDAR_V1: {
108+
pResult = new CCalenderV1();
109+
break;
110+
}
111+
case CALENDAR_V2: {
112+
pResult = new CCalenderV2();
113+
break;
114+
}
115+
default:
116+
break;
103117
}
104118
return pResult;
105119
}
106120

107121
// 释放内存
108-
void CCalenderFactory::freeCalender(CCalenderBase* pCalender) { delete pCalender; }
122+
void CCalenderFactory::freeCalender(CCalenderBase* pCalender)
123+
{
124+
delete pCalender;
125+
}
109126

110127
CCalenderBase::CCalenderBase() = default;
111128

@@ -252,4 +269,4 @@ CGanZhi& CGanZhi::operator=(const CGanZhi& ganzhi)
252269
this->m_nYZhi = ganzhi.m_nYZhi;
253270
return *this;
254271
}
255-
} // namespace cppbox
272+
} // namespace cppbox

box_calendar/calendar_base.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct CPP_CALENDAR_API CDate {
5252
CDate(int y, int m, int d);
5353
CDate(const CDate& date);
5454
CDate& operator=(const CDate& date);
55+
bool operator!=(const CDate& date);
5556
int m_nYear = 0;
5657
int m_nMon = 0;
5758
int m_nDay = 0;

box_calendar/calendar_v2.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,27 @@ bool CCalenderV2::setDateTime(const CDateTime& datetime)
5050
break;
5151
}
5252
}
53+
checkMonthGZ();
5354
return true;
5455
}
56+
57+
// 根据节气时间修正月干支
58+
void CCalenderV2::checkMonthGZ()
59+
{
60+
auto ck = [&](const CDateTime& datetime) {
61+
if (m_datetime.m_date != datetime.m_date) {
62+
return ;
63+
}
64+
int df = getDiffByTwoTime(m_datetime.m_time, datetime.m_time);
65+
if (df < 0) {
66+
m_sizhu.m_nMGan = CCalenderBase::getRemainder(10, m_sizhu.m_nMGan - 1);
67+
m_sizhu.m_nMZhi = CCalenderBase::getRemainder(12, m_sizhu.m_nMZhi - 1);
68+
}
69+
};
70+
ck(m_first.datetime);
71+
ck(m_second.datetime);
72+
}
73+
5574
// 获取前一天
5675
void CCalenderV2::getPreDay(CDateTime& datetime) { getPreDay(datetime.m_date); }
5776

box_calendar/calendar_v2.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class CCalenderV2 : public CCalenderBase
4040
void sxday2DateTimeLunar(Day* day, CDate& date);
4141
void sxday2DateTimeSolar(Day* day, CDate& date);
4242
int roundDouble(double number);
43+
// 根据节气时间修正月干支
44+
void checkMonthGZ();
4345

4446
private:
4547
Day* day_{};

0 commit comments

Comments
 (0)