summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-02-13 22:57:19 +0800
committerWe-unite <3205135446@qq.com>2025-02-13 22:57:19 +0800
commit201b76d9725df81c828845a59c9077c5d5854c6e (patch)
tree4f80fb99f36c59bb1e79409544b42e0bd07e6c46
parent644f678387cd81a87bd0c73ea0123c825bc99e59 (diff)
downloadcalendar-master.tar.gz
calendar-master.zip
无中气置闰,每个月的界限是按日,而非按朔的时刻HEADmaster
-rw-r--r--src/List.cpp9
-rw-r--r--src/calendar.cpp43
2 files changed, 15 insertions, 37 deletions
diff --git a/src/List.cpp b/src/List.cpp
index b4600bc..67af9ce 100644
--- a/src/List.cpp
+++ b/src/List.cpp
@@ -1,4 +1,5 @@
1#include "calendar.h" 1#include "calendar.h"
2#include <cstdio>
2 3
3List::List() { 4List::List() {
4 // 为方便初始化,链表头结点设为空节点,注意不要使用 5 // 为方便初始化,链表头结点设为空节点,注意不要使用
@@ -116,8 +117,12 @@ void List::Run() {
116 int i = 0, j = 0; 117 int i = 0, j = 0;
117 int mon_index = 11; 118 int mon_index = 11;
118 bool flag; 119 bool flag;
119 while (later(zhongqi_vec[12], shuori_vec[i])) { 120 point *p = head->next->next;
120 i++; 121
122 while (!(p->isZhongqi && p->JieqiIndex == 24)) {
123 if (p->isShuo)
124 i++;
125 p = p->next;
121 } 126 }
122 127
123 if (i == 13) { 128 if (i == 13) {
diff --git a/src/calendar.cpp b/src/calendar.cpp
index dcb96d7..7f64baa 100644
--- a/src/calendar.cpp
+++ b/src/calendar.cpp
@@ -50,57 +50,30 @@ void JieQi(Date *date) {
50 t = julian.getJulianKiloYear(time); 50 t = julian.getJulianKiloYear(time);
51 t_end = julian.getJulianKiloYear(time + day); 51 t_end = julian.getJulianKiloYear(time + day);
52 52
53 //定春分
54 if (target_angle == 0) { 53 if (target_angle == 0) {
55 /* 春分太阳地心视黄经为0,一般二分法不便于计算 54 while (p.sun_longitude(t_end) > 300) {
56 * 因而限定范围为[355,360)∪(0,5],即春分前后各5度
57 * 当t_end时刻太阳地心视黄经在[355,360)时,证明春分在后边,t和t_end前进24h
58 */
59 while (p.sun_longitude(t_end) < 360 &&
60 p.sun_longitude(t_end) > 355) {
61 time += day; 55 time += day;
62 t = t_end; 56 t = t_end;
63 t_end = julian.getJulianKiloYear(time + day); 57 t_end = julian.getJulianKiloYear(time + day);
64 } 58 }
65 /* 循环体time每次在已经计算出的上一节气基础上前进12日,理论上春分在t_end之后 59 if (!(p.sun_longitude(t) > 300 && p.sun_longitude(t_end) < 2)) {
66 * 当跳出上一while循环时理论上春分时刻正在t与t_end之间 60 fprintf(stderr, "Error: Can't find the target angle\n");
67 * 为保险起见,添加这个循环 61 exit(1);
68 * 当t时刻太阳地心视黄经在[0,5]时,证明春分在前边,t和t_end后退24h
69 */
70 while (p.sun_longitude(t) < 5) {
71 time -= day;
72 t_end = t;
73 t = julian.getJulianKiloYear(time);
74 } 62 }
75
76 //二分法计算春分
77 while (t_end - t > delta) { 63 while (t_end - t > delta) {
78 t_middle = (t + t_end) / 2; 64 t_middle = (t + t_end) / 2;
79 if (p.sun_longitude(t_middle) < 360 && 65 if (p.sun_longitude(t_middle) < 2) {
80 p.sun_longitude(t_middle) > 355) {
81 t = t_middle;
82 } else {
83 t_end = t_middle; 66 t_end = t_middle;
67 } else {
68 t = t_middle;
84 } 69 }
85 } 70 }
86 } 71 } else {
87 //其他情况
88 else {
89 //当t_end时刻太阳地心视黄经小于目标角度,节气在后,t和t_end前进24h
90 while (p.sun_longitude(t_end) < target_angle) { 72 while (p.sun_longitude(t_end) < target_angle) {
91 time += day; 73 time += day;
92 t = t_end; 74 t = t_end;
93 t_end = julian.getJulianKiloYear(time + day); 75 t_end = julian.getJulianKiloYear(time + day);
94 } 76 }
95
96 //当t时刻太阳地心视黄经大于目标角度,节气在前,t和t_end后退24h
97 //该循环也是一个保险循环
98 while (p.sun_longitude(t) > target_angle) {
99 time -= day;
100 t_end = t;
101 t = julian.getJulianKiloYear(time);
102 }
103
104 while (t_end - t > delta) { 77 while (t_end - t > delta) {
105 t_middle = (t + t_end) / 2; 78 t_middle = (t + t_end) / 2;
106 if (p.sun_longitude(t_middle) < target_angle) { 79 if (p.sun_longitude(t_middle) < target_angle) {